Created
August 12, 2013 05:54
-
-
Save hazzik/6208523 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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