Module: BindingOfCaller::BindingExtensions
Instance Method Summary collapse
-
#callers ⇒ Array<Binding>
Return bindings for all caller frames.
-
#frame_count ⇒ Fixnum
Number of parent frames available at the point of call.
-
#frame_description ⇒ String
The description of the frame.
-
#frame_type ⇒ Symbol
The type of the frame.
-
#of_caller(n) ⇒ Binding
Retrieve the binding of the nth caller of the current frame.
Instance Method Details
#callers ⇒ Array<Binding>
Return bindings for all caller frames.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/binding_of_caller.rb', line 39 def callers ary = [] n = 0 loop do begin ary << Binding.of_caller(n) rescue break end n += 1 end ary.drop_while do |v| !(v.frame_type == :method && v.eval("__method__") == :callers) end.drop(1) end |
#frame_count ⇒ Fixnum
Number of parent frames available at the point of call.
57 58 59 |
# File 'lib/binding_of_caller.rb', line 57 def frame_count callers.size - 1 end |
#frame_description ⇒ String
The description of the frame.
33 34 35 |
# File 'lib/binding_of_caller.rb', line 33 def frame_description @frame_description end |
#frame_type ⇒ Symbol
The type of the frame.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/binding_of_caller.rb', line 63 def frame_type case self.variables.method..to_a.first.to_s when /block/ :block when /eval/ :eval else if frame_description =~ /__(?:class|module)_init__/ :class else :method end end end |
#of_caller(n) ⇒ Binding
Retrieve the binding of the nth caller of the current frame.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/binding_of_caller.rb', line 13 def of_caller(n) bt = Rubinius::VM.backtrace(1 + n, true).first b = Binding.setup( bt.variables, bt.variables.method, bt.static_scope, bt.variables.self, bt ) b.instance_variable_set(:@frame_description, bt.describe) b rescue raise RuntimeError, "Invalid frame, gone beyond end of stack!" end |