Created
February 13, 2017 12:15
-
-
Save pocke/81cc3440ca96251b5b5ac37b63b2da23 to your computer and use it in GitHub Desktop.
This file contains 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
class Binding | |
def return_if(name) | |
eval "return #{name}" if local_variable_get(name) | |
end | |
end | |
def foo(v) | |
binding.return_if(:v) | |
'v is nil' | |
end | |
puts foo(10) # => 10 | |
puts foo(nil) # => 'v is nil' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment