Class: Readapt::Message::Variables
- Defined in:
- lib/readapt/message/variables.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#body, #initialize, run, #set_body
Constructor Details
This class inherits a constructor from Readapt::Message::Base
Instance Method Details
#run ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/readapt/message/variables.rb', line 6 def run ref = arguments['variablesReference'] frame = debugger.frame(ref) # @todo 1 is a magic number representing the toplevel binding (see # Message::Scopes) vars = if ref == 1 global_variables.map do |gv| Variable.new(gv, eval(gv.to_s)) end else if frame != Frame::NULL_FRAME && !frame.nil? frame.locals else obj = References.get(ref) result = [] if obj.is_a?(Array) obj.each_with_index do |itm, idx| result.push Variable.new("[#{idx}]", itm) end elsif obj.is_a?(Hash) obj.each_pair do |idx, itm| result.push Variable.new("[#{idx}]", itm) end else obj.instance_variables.sort.each do |iv| result.push Variable.new(iv, obj.instance_variable_get(iv)) end obj.class.class_variables.sort.each do |cv| result.push Variable.new(cv, obj.class.class_variable_get(cv)) end end result end end set_body({ variables: vars.map do |var| { name: var.name, value: var.value, type: var.type, variablesReference: var.reference } end }) end |