There are three ways to invoke a method. Most of the time you’ll probably only need #1, but #2 and #3 are used when you are doing something called metaprogramming – calling methods based on dynamic information.

1. object =
puts x.some_method
#=> 282660

2. puts x.send(:some_method)
#=> 282660

3. puts x.method(:some_method).call
#=> 282660

Extending this concept a little further is the try method,
which is like send but will do a nil-check on the method first to make sure it is there (and not complain if it is not).

By Jason

Leave a Reply

Your email address will not be published. Required fields are marked *