Ruby dynamic method calling – Khelll's Blog
I’m pretty sure that you have heard lots about ruby, specially as being a dynamic language, you can create methods on the fly, add instance variables, define constants and invoke existing methods dynamically , and that’s what this post is all about.
I’m pretty sure that you have heard lots about ruby, specially as being a dynamic language, you can create methods on the fly, add instance variables, define constants and invoke existing methods dynamically , and that’s what this post is all about :
As you know in ruby you can call a public instance method directly ,ex :
One way to invoke a method dynamically in ruby is to send a message to the object :
A second way is instantiate a method object and then call it:
And the third way is to use the eval method:
Well, when to use what?