Created
June 19, 2018 14:46
-
-
Save flash-gordon/aa2f7a49f55f3b8ff999c4eaf557d374 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
class Matcher | |
def self.[](pattern) | |
Class.new do | |
define_singleton_method(:===) { |exc| pattern === exc.message } | |
end | |
end | |
end | |
begin | |
1 / 0 | |
rescue Matcher[/by 0/] | |
puts 'Rescued!' | |
end | |
__END__ | |
$ ruby test.rb | |
Rescued! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment