An argument list is the ordered collection of values supplied to a method call. Ruby matches those arguments to the method's parameters. Parentheses are optional in many calls, but explicit parentheses improve clarity when calls become complex. section 2.1.3
Supplying one argument
A Celsius-to-Fahrenheit method defines one parameter, c, and receives 100 through its argument list: obj.c2f(100) returns 212.0. The same call can be written as obj.c2f 100, although parentheses are often preferable. section 2.1.3
An argument list is separate from a code block. A call may have arguments, a block, both, or neither; a block is syntax attached to the call, not another argument. section 6.3.3 section 14.1.2
loop { puts "Hi" } # code block but no arguments
loop() { puts "Hi" } # code block, explicit empty argument list
string.scan(/[^,]+/) # one argument, no code block
string.scan(/[^,]+/) {|word| puts word } # one argument and a code block
Compare calls with no arguments, an explicit empty argument list, one argument, and one argument plus a code block. section 6.3.3
Keep these distinctions in mind:
- The argument list itself is not an object; Ruby has no ArgumentList class. The individual arguments are objects. section 14.1.2
- An empty argument list may be written as (), though methods that take no arguments commonly omit the parentheses. section 2.1.3
- Methods can accept required, optional, and default-valued arguments. section 2.6
