28 Jan 2010

Extending Existing Classes in Rails

If you want to make a new class in Rails that isn’t a model or controller, you’ll probably put it into the lib directory. If you name it sensibly, then Rails will automagically find it when you reference it in your code. That’s cool, but if you extend an existing class, Rails will find the existing class, and as such won’t go looking for yours. Therefore you’ll need to require your shiny new alterations explicitly in environment.rb.

require Rails.root.join('lib', 'hash.rb')