Skip to content

Instantly share code, notes, and snippets.

@flash-gordon
Last active December 24, 2015 02:49
Show Gist options
  • Save flash-gordon/6732815 to your computer and use it in GitHub Desktop.
Save flash-gordon/6732815 to your computer and use it in GitHub Desktop.
def yield_and_ensure
yield
ensure
'ensure'
end
def yield_and_return_ensure
yield
ensure
return 'ensure'
end
def without_return
result = yield_and_ensure {return 'block'}
p 'without_return is still running'
result
end
def with_return
result = yield_and_return_ensure {return 'block'}
p 'with_return is still running'
result
end
p without_return
p with_return
# stdout:
# "block"
# "with_return is still running"
# "ensure"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment