Pages

Thursday, January 9, 2014

3 ways to invoke a method in Ruby

You can use following methods to invoke any method in ruby -

object = Object.new

1. The dot operator (or period operator)
puts object.object_id
 #=> 282660

2. The Object#send method
puts object.send(:object_id)
 #=> 282660

3. The method(:foo).call
puts object.method(:object_id).call
 #=> 282660

No comments:

Post a Comment