Information Technology Reference
In-Depth Information
Methods are created using the
def
keyword and can accept arguments (or parameters).
Methods may be invoked by name. Although optional, parentheses are highly recommen-
ded for readability and code portability:
my_method
(
5
)
my_method
5
my
_method
call without parentheses does the same thing.
Methods are also
chainable
in Ruby, so you can continue to call a method on a chain,
provided the return value responds to the method:
"String"
.
upcase
.
downcase
.
reverse
#=> "gnirts"