Skip to content

Instantly share code, notes, and snippets.

@hazzik
Created August 12, 2013 05:54
Show Gist options
  • Save hazzik/6208523 to your computer and use it in GitHub Desktop.
Save hazzik/6208523 to your computer and use it in GitHub Desktop.
def using (v, &block)
begin
block.call
ensure
v.close unless v.nil? if v.class.method_defined? :close
end
end
class Resource
def name ()
return "The emperor"
end
def close()
puts "close called";
end
end
using (v = Resource.new) {
puts "block calling with v.name = " + v.name
raise "error"
puts "block called"
}
v.name()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment