After learning power of Rails framework, I have started learning ruby. In Ruby, I learnt that I can add methods to a class at runtime. In Java, we have to define all methods before compilation. I suppose, this advantage in Ruby gives rise to issues with class dependancies. As I am new to Ruby, could anyone please explain in what way do I lose control by adding methods dynamically.
After learning power of Rails framework, I have started learning ruby. In Ruby, I
Share
Being able to add methods at runtime doesn’t impact the dependencies in any way, or at least not any more than writing any other code would.
The only difference is that you can now have methods “written” as-needed, but you will still have the same dependency issues if you wrote the code yourself. Since ruby is a dynamic language, it’s sense of dependencies is rather different from a more “traditional” statically compiled language like C++ or Java, but even in Java you can load arbitrary code at runtime (it’s much more difficult, but still possible).