def process
obj = args.empty? ? target_self : target.eval(args.join(" "))
has_opts = (opts.present?(:methods) || opts.present?('instance-methods''instance-methods') || opts.present?(:ppp) ||
opts.present?(:globals) || opts.present?(:locals) || opts.present?(:constants) ||
opts.present?(:ivars))
show_methods = opts.present?(:methods) || opts.present?('instance-methods''instance-methods') || opts.present?(:ppp) || !has_opts
show_constants = opts.present?(:constants) || (!has_opts && Module === obj)
show_ivars = opts.present?(:ivars) || !has_opts
show_locals = opts.present?(:locals) || (!has_opts && args.empty?)
grep_regex, grep = [Regexp.new(opts[:G] || "."), lambda{ |x| x.grep(grep_regex) }]
raise Pry::CommandError, "-l does not make sense with a specified Object" if opts.present?(:locals) && !args.empty?
raise Pry::CommandError, "-g does not make sense with a specified Object" if opts.present?(:globals) && !args.empty?
raise Pry::CommandError, "-q does not make sense with -v" if opts.present?(:quiet) && opts.present?(:verbose)
raise Pry::CommandError, "-M only makes sense with a Module or a Class" if opts.present?('instance-methods''instance-methods') && !(Module === obj)
raise Pry::CommandError, "-c only makes sense with a Module or a Class" if opts.present?(:constants) && !args.empty? && !(Module === obj)
if opts.present?(:globals)
output_section("global variables", grep[format_globals(target.eval("global_variables"))])
end
if show_constants
mod = Module === obj ? obj : Object
constants = mod.constants
constants -= (mod.ancestors - [mod]).map(&:constants).flatten unless opts.present?(:verbose)
output_section("constants", grep[format_constants(mod, constants)])
end
if show_methods
methods = all_methods(obj).select{ |method| opts.present?(:ppp) || method.visibility == :public }.group_by(&:owner)
resolution_order(obj).take_while(&below_ceiling(obj)).reverse.each do |klass|
methods_here = format_methods((methods[klass] || []).select{ |m| m.name =~ grep_regex })
output_section "#{Pry::WrappedModule.new(klass).method_prefix}methods", methods_here
end
end
if show_ivars
klass = (Module === obj ? obj : obj.class)
output_section("instance variables", format_variables(:instance_var, grep[obj.__send__(:instance_variables)]))
output_section("class variables", format_variables(:class_var, grep[klass.__send__(:class_variables)]))
end
if show_locals
output_section("locals", format_locals(grep[target.eval("local_variables")]))
end
end