Posts Tagged ‘Meta-Programming’

Did You Know: Ruby Instance Methods

Monday, September 14th, 2009

Did you know that in Ruby you can add new methods to a particular object, as opposed to adding them to the entire class?

Ruby makes it easy to re-open any class to add new methods – that’s almost always covered early on in Ruby books that talk through using the IRB; it’s a great tool for being able to evolve code incrementally as you are scripting the solution. Less common, however is discussion over how to add methods to individual objects; something that feels foreign to a lot of Java developers like myself. It turns out, it’s just as easy as adding methods to the class.
(more…)