Class: LazyGraph::StackPointer
- Inherits:
-
Struct
- Object
- Struct
- LazyGraph::StackPointer
show all
- Defined in:
- lib/lazy_graph/stack_pointer.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/lazy_graph/stack_pointer.rb', line 36
def method_missing(name, *args, &block)
if frame.respond_to?(name)
frame.send(name, *args, &block)
elsif parent
parent.send(name, *args, &block)
else
super
end
end
|
Instance Attribute Details
#depth ⇒ Object
Returns the value of attribute depth
7
8
9
|
# File 'lib/lazy_graph/stack_pointer.rb', line 7
def depth
@depth
end
|
#frame ⇒ Object
Returns the value of attribute frame
7
8
9
|
# File 'lib/lazy_graph/stack_pointer.rb', line 7
def frame
@frame
end
|
#key ⇒ Object
Returns the value of attribute key
7
8
9
|
# File 'lib/lazy_graph/stack_pointer.rb', line 7
def key
@key
end
|
#parent ⇒ Object
Returns the value of attribute parent
7
8
9
|
# File 'lib/lazy_graph/stack_pointer.rb', line 7
def parent
@parent
end
|
#pointer_cache ⇒ Object
Returns the value of attribute pointer_cache.
8
9
10
|
# File 'lib/lazy_graph/stack_pointer.rb', line 8
def pointer_cache
@pointer_cache
end
|
#root ⇒ Object
Returns the value of attribute root
7
8
9
|
# File 'lib/lazy_graph/stack_pointer.rb', line 7
def root
@root
end
|
Instance Method Details
#index ⇒ Object
46
47
48
|
# File 'lib/lazy_graph/stack_pointer.rb', line 46
def index
key
end
|
#log_debug(**log_item) ⇒ Object
50
51
52
53
54
|
# File 'lib/lazy_graph/stack_pointer.rb', line 50
def log_debug(**log_item)
root.frame[:DEBUG] = [] if !root.frame[:DEBUG] || root.frame[:DEBUG].is_a?(MissingValue)
root.frame[:DEBUG] << { **log_item, location: to_s }
nil
end
|
#ptr_at(index) ⇒ Object
31
32
33
34
|
# File 'lib/lazy_graph/stack_pointer.rb', line 31
def ptr_at(index)
@pointer_cache ||= {}.compare_by_identity
@pointer_cache[index] ||= depth == index ? self : parent&.ptr_at(index)
end
|
#push(frame, key) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/lazy_graph/stack_pointer.rb', line 12
def push(frame, key)
if (ptr = POINTER_POOL.pop)
ptr.parent = self
ptr.parent = self
ptr.frame = frame
ptr.key = key
ptr.depth = depth + 1
ptr.pointer_cache&.clear
ptr
else
StackPointer.new(parent: self, frame: frame, key: key, depth: depth + 1, root: root || self)
end
end
|
#recycle! ⇒ Object
26
27
28
29
|
# File 'lib/lazy_graph/stack_pointer.rb', line 26
def recycle!
POINTER_POOL.push(self)
nil
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
56
57
58
|
# File 'lib/lazy_graph/stack_pointer.rb', line 56
def respond_to_missing?(name, include_private = false)
frame.respond_to?(name, include_private) || parent.respond_to?(name, include_private)
end
|
#shifted_id ⇒ Object
10
|
# File 'lib/lazy_graph/stack_pointer.rb', line 10
def shifted_id = @shifted_id ||= object_id << 28
|
#to_s ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/lazy_graph/stack_pointer.rb', line 60
def to_s
if parent
"#{parent}#{key.to_s =~ /\d+/ ? "[#{key}]" : ".#{key}"}"
else
key.to_s
end
end
|