Module: BindingOfCaller::BindingExtensions
- Defined in:
- lib/binding_of_caller/mri.rb,
lib/binding_of_caller/rubinius.rb,
lib/binding_of_caller/jruby_interpreted.rb
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(index = 1) ⇒ Binding
Retrieve the binding of the nth caller of the current frame.
Instance Method Details
#callers ⇒ Array<Binding>
Return bindings for all caller frames.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/binding_of_caller/mri.rb', line 18 def callers ary = [] DebugInspector.open do |dc| locs = dc.backtrace_locations locs.size.times do |i| b = dc.frame_binding(i) if b b.instance_variable_set(:@iseq, dc.frame_iseq(i)) ary << b end end end ary.drop(1) end |
#frame_count ⇒ Fixnum
Number of parent frames available at the point of call.
38 39 40 |
# File 'lib/binding_of_caller/mri.rb', line 38 def frame_count callers.size - 1 end |
#frame_description ⇒ String
The description of the frame.
54 55 56 57 |
# File 'lib/binding_of_caller/mri.rb', line 54 def frame_description return nil if !@iseq @frame_description ||= @iseq.label end |
#frame_type ⇒ Symbol
The type of the frame.
44 45 46 47 48 49 50 |
# File 'lib/binding_of_caller/mri.rb', line 44 def frame_type return nil if !@iseq # apparently the 9th element of the iseq array holds the frame type # ...not sure how reliable this is. @frame_type ||= @iseq.to_a[9] end |
#of_caller(index = 1) ⇒ Binding
Retrieve the binding of the nth caller of the current frame.
7 8 9 10 11 12 13 14 |
# File 'lib/binding_of_caller/mri.rb', line 7 def of_caller(n) c = callers.drop(1) if n > (c.size - 1) raise "No such frame, gone beyond end of stack!" else c[n] end end |