Friday, August 30, 2013

Ruby - writing a method without a "parameter"

Ruby - writing a method without a "parameter"

For example, the array class has a method named ".sort" that you call on
an array with the following syntax:
[2, 3, 4, 1].sort
From my limited knowledge, I only know how to write methods that take an
actual parameter:
def sort(array)
...
end
and are called as such:
sort([2, 3, 4, 1])
How would you go about setting up a method that can be called with the dot
notation (please correct me if I'm wrong) syntax?

No comments:

Post a Comment