Last active
October 10, 2016 21:11
-
-
Save madgen/18fbe3962a87cd111e1345513e752540 to your computer and use it in GitHub Desktop.
Assign to free variable of a block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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