Making Quick Exception Classes: Will the Monkey Dance?
Making Quick Exception Classes: Will the Monkey Dance? Tuesday May 12, 2009 On the Ruby Best Practices blog , Gregory Brown wrote an interesting article about a quick way for making exception classes. Interesting as it is, we believe that we can take what he has done a bit further. Brown shows you how to use Class.new and anonymous classes, which is interesting and gets the job done, it’s not necessarily as Rubyish as it could be. Even if you wrap it up in a loop, defining your exceptions as a list, it can still be better. How? By implementing an exceptions helper, just like attr_reader or attr_accessor. It’s implemented by defining a method of the class Module. In this quick tip for making quick exception classes, we’ll show you how to do it. Since, in the example, the Monkey won’t dance if he’s hungry or tired, among other