Skip to content

Instantly share code, notes, and snippets.

@jonfuller
Forked from Ball/gist:3986836
Created October 31, 2012 12:56
Show Gist options
  • Save jonfuller/3986883 to your computer and use it in GitHub Desktop.
Save jonfuller/3986883 to your computer and use it in GitHub Desktop.
Defer / disposable in ruby
def using(to_ensure)
begin
yield if block_given?
ensure
to_ensure()
end
obj = SomthingToClose.connect
records = []
using( -> obj.close) do
records = obj.get_all_the_things
process(records)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment