Class: Recursivar::Heap
- Includes:
- Enumerable
- Defined in:
- lib/recursivar/heap.rb
Defined Under Namespace
Classes: Value
Instance Attribute Summary collapse
-
#heap ⇒ Object
readonly
Returns the value of attribute heap.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(stack) ⇒ Heap
constructor
A new instance of Heap.
- #link_callee(callor, callee, level) ⇒ Object
- #ref(obj) ⇒ Object
- #wrap_caller(callor) ⇒ Object
Constructor Details
#initialize(stack) ⇒ Heap
Returns a new instance of Heap.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/recursivar/heap.rb', line 39 def initialize(stack) @heap = {} stack.each_with_index do |callor, idx| local_values = {} callor.lv.each_pair do |name, obj| local_values[name] = ref(obj) end callor_v = wrap_caller(callor) callor_v.values.merge!(local_values) callee = stack[idx - 1] link_callee(callor_v, callee, "#{idx} #{callee.frame_env}") if idx > 0 end end |
Instance Attribute Details
#heap ⇒ Object (readonly)
Returns the value of attribute heap.
37 38 39 |
# File 'lib/recursivar/heap.rb', line 37 def heap @heap end |
Instance Method Details
#each ⇒ Object
74 75 76 |
# File 'lib/recursivar/heap.rb', line 74 def each @heap.each_pair{ |_, v| yield(v) } end |
#link_callee(callor, callee, level) ⇒ Object
56 57 58 59 |
# File 'lib/recursivar/heap.rb', line 56 def link_callee(callor, callee, level) callee = @heap[callee.send(:binding_self).object_id] callor.add_callee(callee, level) end |
#ref(obj) ⇒ Object
66 67 68 69 70 |
# File 'lib/recursivar/heap.rb', line 66 def ref(obj) v = (@heap[obj.object_id] ||= Value.new(obj)) v.ref_instance_variables(self) v end |
#wrap_caller(callor) ⇒ Object
61 62 63 64 |
# File 'lib/recursivar/heap.rb', line 61 def wrap_caller(callor) callor_obj = callor.send(:binding_self) ref(callor_obj) end |