Dynamic method calls in Ruby

Ruby is a dynamic language. One of the coolest feature is the dynamic method call. Image you have a Integer Object.

a = 5

On every Object you can call the “to_s” method, that will convert it to String.

a.to_s

Will return the String representation of 5 that is “5”. But you can also call the method in a dynamic way:

a.send("to_s")

That is cool! Int that way you can make method calls dynamically and configurable.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s