Friday, September 16, 2011

The Ultimate Base Class

An interesting proof-of-concept ruby library called Base (source) was released last week - at least I hope it is not a serious project!.

The author describes it like this:

People love Base classes! They have tons of methods waiting to be used. Just check out ActiveRecord::Base's method list:

>> ActiveRecord::Base.methods.length
=> 530

But why stop there? Why not have even more methods? In fact, let's put every method on one Base class!

Yep, I've got to agree that many developers I've worked with love making beefy base classes.

So how does Base work? First, you create a class that inherits from Base like so:

class Utility < Base

and through the magic of ruby's method_missing it will effectively attach every method of every Module in its runtime environment (which will be quite a few if running under Rails, for example) to your class.

And what happens if two or more modules have the same method name? You'll get the first one that was loaded!

I like it! Now we need one database table to rule them all!


Suseela Susiee said...

Awesome article. It is so detailed and well formatted that i enjoyed reading it as well as get some new information too.

SAP ABAP Training in Chennai

SAP HR training in Chennai

Philips Huges said...

Wonderful blog.. Thanks for sharing informative Post. Its very useful to me.

Installment loans
Payday loans
Title loans