Skip to content

Instantly share code, notes, and snippets.

@steveklabnik
Created December 7, 2011 13:28
Embed
What would you like to do?
fun with bindings
def with_binding(b)
vars = eval('local_variables', b)
vars.each do |v|
eval("#{v} = #{eval(v.to_s, b)}")
end
yield
end
a = 5
with_binding(binding()) do
puts a
end
@erithmetic
Copy link

Problem? :^)

@steveklabnik
Copy link
Author

Because it's the morning, I forgot that the block would already capture the binding...

def whatevs
  yield
end

a = 5

whatevs do
  puts a
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment