Skip to content

Instantly share code, notes, and snippets.

@flash-gordon
Created June 19, 2018 14:46
Show Gist options
  • Save flash-gordon/aa2f7a49f55f3b8ff999c4eaf557d374 to your computer and use it in GitHub Desktop.
Save flash-gordon/aa2f7a49f55f3b8ff999c4eaf557d374 to your computer and use it in GitHub Desktop.
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