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