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
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