rails/rails — pull request #17980 by gsamokovarov (2014-12-09 10:25:23+00:00)
Title: Add class level case operator support for error dispatching in Rescuable

Ruby rescue dispatches exceptions by calling a class level case operator. Take this one as an example:

```ruby
module ErrorDispatcher
def self.===(other)
Exception === other
end
end

begin
raise
rescue ErrorDispatcher
puts "Yep, it is dispatched."
end
```

I'm proposing to add this support to `ActiveSupport::Rescuable`. I wanted to do this in an application, where we already had a global `rescue_from`. I didn't wanted to introduce another one, for the same dispatching logic and put a class level case operator on a specific error. I don't expect this to be a common case, but I like the symmetry with Ruby's rescue.

A couple of technicalities: I didn't change the current error message, because I think its clear enough and I don't know how to explain all that semantics in a reasonable message :disappointed_relieved: I also kept a couple of `klass` references for a cleaner diff.

Ruby's rescue requires the target to be a `Module`. So we can't go for object level case operator support.