class Byebug::MethodCommand

Implements byebug’s ‘method’ command.

def description

def description
  %{m[ethod] i[nstance] <obj>\tshow methods of object
    m[ethod] iv <obj>\t\tshow instance variables of object
    m[ethod] <class|module>\t\tshow instance methods of class or module}
end

def execute

def execute
  obj = debug_eval(@match.post_match)
  if @match[1] == "iv"
    obj.instance_variables.sort.each do |v|
      print "#{v} = #{obj.instance_variable_get(v).inspect}\n"
    end
  elsif @match[1]
    print "#{columnize(obj.methods.sort(), Command.settings[:width])}\n"
  else
    return print "Should be Class/Module: #{@match.post_match}\n" unless
      obj.kind_of? Module
    print "#{columnize(obj.instance_methods(false).sort(),
                       Command.settings[:width])}\n"
  end
end

def names

def names
  %w(method)
end

def regexp

def regexp
  /^\s* m(?:ethod)? \s+ ((iv)|(i(:?nstance)?)\s+)?/x
end