Skip to content

Instantly share code, notes, and snippets.

@pocke
Created February 13, 2017 12:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pocke/81cc3440ca96251b5b5ac37b63b2da23 to your computer and use it in GitHub Desktop.
Save pocke/81cc3440ca96251b5b5ac37b63b2da23 to your computer and use it in GitHub Desktop.
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