Ruby methods are objects

Posted by Steven Soroka 03 Mar 2010

You may know that everything in Ruby is an object, but did you know that methods are objects?

my_string = "test"
size_method = my_string.method(:size)
size_method.arity   # 0

size_method.call  # 4

You can request a method’s arity (basically the number of parameters it takes), call it, or even convert it to a proc and pass it to another method. Interesting, n’est pas?