Created
May 23, 2013 17:02
-
-
Save gstark/5637637 to your computer and use it in GitHub Desktop.
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
# Assuming the exception is something like this | |
module Flicker | |
class ApiError < StandardError | |
end | |
end | |
def error_with_message(pattern) | |
error_handling_module = Module.new | |
(class << error_handling_module; self; end).instance_eval do | |
define_method(:===) do |exception| | |
pattern === exception.message | |
end | |
end | |
end | |
begin | |
raise Flicker::ApiError, "thing you want to match" | |
rescue error_with_message(/match/) | |
puts "I got ya!" | |
end | |
begin | |
raise Flicker::ApiError, "This isn't going to work" | |
rescue error_with_message(/match/) | |
puts "I got ya!" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment