This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Mixing in singleton methods
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
I released facade 1.0.3 today. I don't know if I've blogged about it before so I thought I would mention it. In short, it lets you mix in (all or some) singleton methods from a class or module, and turn them into instance methods of the extending class without overriding any existing methods.
For example, there are several singleton methods of the File class, such as File.basename, File.dirname, etc. What if you want to mix them into the String class directly as instance methods? Here's how you do it: