Class: Debugger::VarInstanceCommand

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

Overview

:nodoc:

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

Constructor Details

This class inherits a constructor from Debugger::Command

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Debugger::Command

Class Method Details

.help(cmd) ⇒ Object



108
109
110
111
112
# File 'lib/ruby-debug/commands/variables.rb', line 108

def help(cmd)
  %{
    v[ar] i[nstance] <object>\tshow instance variables of object, object can be given by its id or an expression
  }
end

.help_commandObject



104
105
106
# File 'lib/ruby-debug/commands/variables.rb', line 104

def help_command
  'var'
end

Instance Method Details

#executeObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/ruby-debug/commands/variables.rb', line 67

def execute
  if (@match[1])
    obj = ObjectSpace._id2ref(@match[1].hex) rescue nil
    unless obj
      # TODO: ensure that empty variables frame will be printed
      @printer.print_msg("Unknown object id : %s", @match[1])
    end
  else
    obj = debug_eval(@match.post_match)
  end
  return unless obj
  if (obj.is_a?(Array)) then
    print_array(obj)
  elsif (obj.is_a?(Hash)) then
    print_hash(obj)
  else
    print_element("variables") do
      # instance variables
      kind = 'instance'
      inst_vars = obj.instance_variables
      instance_binding = obj.instance_eval{binding()}
      # print self at top position
      print_variable('self', debug_eval('self', instance_binding), kind) if inst_vars.include?('self')
      inst_vars.sort.each do |var|
        print_variable(var, debug_eval(var, instance_binding), kind) unless var == 'self'
      end
      
      # class variables
      class_binding = obj.class.class_eval('binding()')
      obj.class.class_variables.sort.each do |var|
        print_variable(var, debug_eval(var, class_binding), 'class')
      end
    end
  end 
end

#regexpObject



62
63
64
65
# File 'lib/ruby-debug/commands/variables.rb', line 62

def regexp
  # id will be read as first match, name as post match
  /^\s*v(?:ar)?\s+i(?:nstance)?\s+((?:[\\+-]0x)[\dabcdef]+)?/
end