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



71
72
73
74
75
76
77
# File 'lib/ruby-debug/commands/method.rb', line 71

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



67
68
69
# File 'lib/ruby-debug/commands/method.rb', line 67

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
# File 'lib/ruby-debug/commands/method.rb', line 48

def execute
  result = if @match[1] == "iv"
    obj = debug_eval(@match.post_match)
    variables = obj.instance_variables.sort.map { |var_name| [var_name, obj.instance_variable_get(var_name)] }
    prv(variables, 'instance')
  elsif @match[1]
    prc("method.methods", debug_eval(@match.post_match).methods.sort) { |item, _| {name: item} }
  else
    obj = debug_eval(@match.post_match)
    if obj.kind_of?(Module)
      prc("method.methods", obj.instance_methods(false).sort) { |item, _| {name: item} }
    else
      errmsg(pr("variable.errors.not_class_module", object: @match.post_match)) && return
    end
  end
  print result
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