Guest User

Untitled

a guest
Feb 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. def f(&b)
  2. var_inside_method = :foo
  3.  
  4. binding_of_this_method = binding
  5. binding_of_block = b.binding
  6. binding_inside_block = b.call
  7.  
  8. eval "p local_variables", binding_of_this_method
  9. eval "p local_variables", binding_of_block
  10. eval "p local_variables", binding_inside_block
  11. end
  12.  
  13. var_outside_proc = :foo
  14.  
  15. f { var_inside_proc = :foo; binding }
  16.  
  17. # Results:
  18. # ["b", "var_inside_method", "binding_of_this_method", "binding_of_block", "binding_inside_block"]
  19. # ["var_outside_proc"]
  20. # ["var_outside_proc", "var_inside_proc"]
Add Comment
Please, Sign In to add comment