What I learned from Rails

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

One thing I learned from Rails: meta-programming is crucial if you want to take advantage of 3rd party code. In the world of PHP, you can only use people’s 3rd party code if you are using some framework that allows plugins, such as WordPress. And, generally, the plugins are only allowed to override certain parts of the framework.

With Rails, if you find 5 useful gems from 5 different developers, and all 5 gems alter the way your database classes work, you just add the gems to your project. Simple as that. Each gem will open up the classes that work with your models and databases, and they will add their code.

In an OOP language like PHP, you can sort of get that effect by over-riding a class. Maybe you have a class called database.php and some other developer came up with a much better version, so you add their database.php to your lib or vendors folder and it overrides the default database.php.

But the OOP method is extremely limited: you are overriding one file, which makes it tough to add 5 different things from 5 different developers. In Ruby, a class definition can be reopened from any file, so all 5 developers can reopen the core classes of Rails and add in new functionality. It would be very difficult to imitate that in PHP.

Source