Skip to content

Instantly share code, notes, and snippets.

@gstark
Created May 23, 2013 17: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 gstark/5637637 to your computer and use it in GitHub Desktop.
Save gstark/5637637 to your computer and use it in GitHub Desktop.
# 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