Class: Debugger::VarInstanceCommand

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

Overview

:nodoc:

Constant Summary collapse

BINDING_COMMAND =

TODO: try to find out a way to use Kernel.binding for Rubinius ::Kernel.binding doesn't for for ruby 1.8 (see RUBY-14679)

(Rubinius) || RUBY_VERSION < '1.9') ? 'binding' : '::Kernel.binding'

Constants inherited from Command

Command::DEF_OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, file_filter_supported?, #find, inherited, #initialize, load_commands, #match, method_missing, options, unescape_incoming

Constructor Details

This class inherits a constructor from Debugger::Command

Class Method Details

.help(cmd) ⇒ Object


115
116
117
118
119
# File 'lib/ruby-debug-ide/commands/variables.rb', line 115

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


111
112
113
# File 'lib/ruby-debug-ide/commands/variables.rb', line 111

def help_command
  'var'
end

Instance Method Details

#executeObject


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
102
103
104
105
106
107
108
# File 'lib/ruby-debug-ide/commands/variables.rb', line 71

def execute
  if (@match[1])
    obj = ObjectSpace._id2ref(@match[1].hex) rescue nil

    unless obj
      print_element("variables")
      @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)
    print_array(obj)
  elsif obj.is_a?(Hash)
    print_hash(obj)
  elsif obj.is_a?(String)
    print_string(obj)
  else
    print_element("variables") do
      # instance variables
      kind = 'instance'
      inst_vars = obj.instance_variables
      instance_binding = obj.instance_eval(BINDING_COMMAND)
      # 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_COMMAND)
      obj.class.class_variables.sort.each do |var|
        print_variable(var, debug_eval(var, class_binding), 'class')
      end
    end
  end 
end

#regexpObject


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

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