class Delfos::CallStack::Stack
Attributes
call_sites[W]
execution_count[W]
stack_depth[W]
step_count[W]
Public Class Methods
new(on_empty: nil)
click to toggle source
# File lib/delfos/call_stack/stack.rb, line 5 def initialize(on_empty: nil) @on_empty = on_empty end
Public Instance Methods
call_sites()
click to toggle source
# File lib/delfos/call_stack/stack.rb, line 39 def call_sites @call_sites ||= [] end
execution_count()
click to toggle source
# File lib/delfos/call_stack/stack.rb, line 35 def execution_count @execution_count ||= 0 end
pop()
click to toggle source
# File lib/delfos/call_stack/stack.rb, line 16 def pop popping_empty_stack! if self.stack_depth.zero? self.stack_depth -= 1 if stack_depth.zero? && call_sites.length.positive? @on_empty&.call(call_sites, execution_count) self.call_sites = [] end end
pop_until_top!()
click to toggle source
# File lib/delfos/call_stack/stack.rb, line 27 def pop_until_top! pop while self.stack_depth.positive? end
push(method_object)
click to toggle source
# File lib/delfos/call_stack/stack.rb, line 9 def push(method_object) call_sites.push(method_object) self.stack_depth += 1 self.execution_count += self.stack_depth == 1 ? 1 : 0 end
stack_depth()
click to toggle source
# File lib/delfos/call_stack/stack.rb, line 31 def stack_depth @stack_depth ||= 0 end
step_count()
click to toggle source
# File lib/delfos/call_stack/stack.rb, line 43 def step_count call_sites.length end
Private Instance Methods
popping_empty_stack!()
click to toggle source
# File lib/delfos/call_stack/stack.rb, line 51 def popping_empty_stack! raise PoppingEmptyStackError end