# File lib/pry/default_commands/ls.rb, line 44
        def process
          obj = args.empty? ? target_self : target.eval(args.join(" "))

          # exclude -q, -v and --grep because they don't specify what the user wants to see.
          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_self_methods = (!has_opts && Module === obj)
          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 is a hash {Module/Class => [Pry::Methods]}
            methods = all_methods(obj).group_by(&:owner)

            # reverse the resolution order so that the most useful information appears right by the prompt
            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_self_methods
            methods = all_methods(obj, true).select{ |m| m.owner == obj && m.name =~ grep_regex }
            output_section "#{Pry::WrappedModule.new(obj).method_prefix}methods", format_methods(methods)
          end

          if show_ivars
            klass = (Module === obj ? obj : obj.class)
            ivars = Pry::Method.safe_send(obj, :instance_variables)
            kvars = Pry::Method.safe_send(klass, :class_variables)
            output_section("instance variables", format_variables(:instance_var, ivars))
            output_section("class variables", format_variables(:class_var, kvars))
          end

          if show_locals
            output_section("locals", format_locals(grep[target.eval("local_variables")]))
          end
        end