Skip to content

Instantly share code, notes, and snippets.

@technohippy
Created May 11, 2012 02:03
Show Gist options
  • Save technohippy/2657058 to your computer and use it in GitHub Desktop.
Save technohippy/2657058 to your computer and use it in GitHub Desktop.
class CodedException < Exception
attr_accessor :code
def initialize(code, msg='')
super msg
@code = code
end
end
class Range
def ===(obj)
if obj.kind_of? CodedException
self === obj.code
else
self.begin <= obj and (self.exclude_end? ? obj < self.end : obj <= self.end)
end
end
end
begin
raise CodedException.new(250, 'message')
rescue 0..99
puts :e0
rescue 100..199
puts :e100
rescue 200..299
puts :e200
end
#=> e200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment