1 | |
2 | def create_context(x) |
3 | y = 20 |
4 | binding |
5 | end |
6 | |
7 | binding = create_context(10) |
8 | puts binding |
9 | puts binding.class |
10 | |
11 | vars = binding.eval("local_variables") |
12 | puts vars |
13 | puts vars.class |
14 | |
15 | # Why doesn't this work? |
16 | #myproc = proc { puts "x: #{x}, y: #{y}" } |
17 | |
18 | # You need this longer thing |
19 | myproc = proc { puts "x: #{binding.eval("x")}, y: #{binding.eval("y")}" } |
20 | |
21 | # Execute the block in the context |
22 | binding.instance_exec(&myproc) |
23 |