Skip to content

Instantly share code, notes, and snippets.

@maraigue
Created May 27, 2012 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maraigue/2802352 to your computer and use it in GitHub Desktop.
Save maraigue/2802352 to your computer and use it in GitHub Desktop.
Rubyのrescue演算子に例外クラスが指定できないので無理やり指定できるようにしてみた(その2)
# その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