Class: Debugger::MethodCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/ruby-debug/commands/method.rb

Overview

Implements the debugger ‘method’ command.

Constant Summary

Constants inherited from Command

Command::DEF_OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, #find, inherited, #initialize, load_commands, #match, method_missing, options, register_setting_get, register_setting_set, register_setting_var, settings, settings_map

Constructor Details

This class inherits a constructor from Debugger::Command

Class Method Details

.help(cmd) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/ruby-debug/commands/method.rb', line 74

def help(cmd)
  %{
    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

.help_commandObject



70
71
72
# File 'lib/ruby-debug/commands/method.rb', line 70

def help_command
  'method'
end

Instance Method Details

#executeObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ruby-debug/commands/method.rb', line 48

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

#regexpObject



44
45
46
# File 'lib/ruby-debug/commands/method.rb', line 44

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