Skip to content

Instantly share code, notes, and snippets.

@Ball
Created October 31, 2012 12:40
Show Gist options
  • Save Ball/3986836 to your computer and use it in GitHub Desktop.
Save Ball/3986836 to your computer and use it in GitHub Desktop.
Defer / disposable in ruby
def using(object, message, *args)
begin
yield if block_given?
ensure
object.send(message, *args)
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