Skip to content

Instantly share code, notes, and snippets.

@madgen
Last active October 10, 2016 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madgen/18fbe3962a87cd111e1345513e752540 to your computer and use it in GitHub Desktop.
Save madgen/18fbe3962a87cd111e1345513e752540 to your computer and use it in GitHub Desktop.
Assign to free variable of a block
def clean_dispatch(&block)
b = block.binding
locals = b.local_variables
params = block.parameters
locals.each do |var|
b.local_variable_set(var, nil) unless params.include? var
end
yield
end
a = 1
clean_dispatch { puts a }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment