Skip to content

Instantly share code, notes, and snippets.

@pocke pocke/return_if.rb
Created Feb 13, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.