Created
May 27, 2012 06:02
-
-
Save maraigue/2802352 to your computer and use it in GitHub Desktop.
Rubyのrescue演算子に例外クラスが指定できないので無理やり指定できるようにしてみた(その2)
This file contains 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
# その1: http://gist.github.com/2802312 | |
class Proc | |
def rescue(klass, value) | |
begin | |
self.call | |
rescue klass | |
return value | |
end | |
end | |
end | |
->{ open("hoge") }.rescue(StandardError, nil) | |
# => nil | |
->{ open("hoge") }.rescue(ZeroDivisionError, nil) | |
# 例外発生 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment