File: example.rb

package info (click to toggle)
ruby-binding-of-caller 0.7.2%2Bdebian1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 176 kB
  • ctags: 65
  • sloc: ruby: 308; ansic: 173; makefile: 9
file content (41 lines) | stat: -rw-r--r-- 656 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
unless Object.const_defined? :BindingOfCaller
  $:.unshift File.expand_path '../../lib', __FILE__
  require 'binding_of_caller'
  require 'binding_of_caller/version'
end

outer = 10

class Z
  def z
    u = 10
    A.new.a
  end
end

class A
  def a
    y = 10
    B.new.b
  end
end

class B
  def b
    x = 10
    puts binding.of_caller(0).eval('local_variables')
    puts binding.of_caller(1).eval('local_variables')
    puts binding.of_caller(2).eval('local_variables')
    puts binding.of_caller(3).eval('local_variables')
    puts binding.of_caller(400).eval('local_variables')
  end
end

Z.new.z

# output:
# => x
# => y
# => u
# => outer
# Exception