The biggest difference really comes down to metaprogramming. While Java offers introspection (which was a major step up from C++), Ruby offers the ability to dynamically define new classes and methods without recompilation. Additionally, the ability to hook into a module being included or a new class being sub-classed combined with metaprogramming adds extremely powerful new capabilities. This is why in Rails I can sub-class from the model class and automatically have all the methods available to me for CRUD operations for my database entities.
In other words, I can create and use frameworks that leverage metaprogramming to make their use by end-users almost trivial.
Nonetheless, my love of Ruby does not cause me to knock Java. I still enjoy coding in Java, and one should use the right tool for the job.
In order to be a better Rails and Ruby developer, I studied Pragmatic Programmer’s “Metaprogramming Ruby” (thumbs up). By study, I mean read, took notes, created flash cards, wrote sample code and played, then finally created a suite of RUnit tests to exercise all the various capabilities. “Mastering” Ruby metaprogramming greatly expanded my understanding of how Rails works under the covers.
I was surprised by how much Ruby metaprogramming had in common with JavaScript metaprogramming (such as dynamically defining methods). Once again, this is one of the benefits of studying different languages – seeing the common patterns that emerge.
The next few blogs I do will go into Ruby metaprogramming.