Module: BindingOfCaller::BindingExtensions
- Defined in:
- lib/binding_of_caller/mri2.rb,
lib/binding_of_caller/rubinius.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(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.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/binding_of_caller/mri2.rb', line 18 def callers ary = [] RubyVM::DebugInspector.open do |i| n = 0 loop do begin b = i.frame_binding(n) if b iseq = i.frame_iseq(n) b.instance_variable_set(:@iseq, iseq) ary << b end rescue ArgumentError break end n += 1 end end ary.drop(1) end |
#frame_count ⇒ Fixnum
Number of parent frames available at the point of call.
44 45 46 |
# File 'lib/binding_of_caller/mri2.rb', line 44 def frame_count callers.size - 1 end |
#frame_description ⇒ String
The description of the frame.
60 61 62 63 |
# File 'lib/binding_of_caller/mri2.rb', line 60 def frame_description return nil if !@iseq @frame_description ||= @iseq.label end |
#frame_type ⇒ Symbol
The type of the frame.
50 51 52 53 54 55 56 |
# File 'lib/binding_of_caller/mri2.rb', line 50 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(n) ⇒ 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/mri2.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 |