Methods

Methods

Methods implement the functionality of your program. Here is a simple method definition:

def one_plus_one
  1 + 1
end

A method definition consists of the def keyword, a method name, the body of the method, return value and the end keyword. When called the method will execute the body of the method. This method returns 2.

This section only covers defining methods. See also the syntax documentation on calling methods.

Method Names

Method names may be one of the operators or must start a letter or a character with the eight bit set. It may contain letters, numbers, an _ (underscore or low line) or a character with the eight bit set. The con