Skip to content

Instantly share code, notes, and snippets.

@alloy
Forked from mmower/gist:6338
Created August 20, 2008 08:07
Show Gist options
  • Select an option

  • Save alloy/6339 to your computer and use it in GitHub Desktop.

Select an option

Save alloy/6339 to your computer and use it in GitHub Desktop.
def f(&b)
var_inside_method = :foo
binding_of_this_method = binding
binding_of_block = b.binding
binding_inside_block = b.call
eval "p local_variables", binding_of_this_method
eval "p local_variables", binding_of_block
eval "p local_variables", binding_inside_block
end
var_outside_proc = :foo
f { var_inside_proc = :foo; binding }
# Results:
# ["b", "var_inside_method", "binding_of_this_method", "binding_of_block", "binding_inside_block"]
# ["var_outside_proc"]
# ["var_outside_proc", "var_inside_proc"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment