A method name is a Ruby identifier that names the operation being called. In a method call, the name is required; the receiver may be explicit or may default to self, while arguments and a code block are optional. section 1.1.3 section 6.3.3
Recognize method names by contrasting them with nearby Ruby identifier categories:
- Local variables begin with a lowercase letter or underscore and use letters, underscores, and digits; method names belong to a separate identifier category. section 1.1.3
- A method call can combine a method name with an explicit receiver, an argument list, a code block, or none of the optional parts. section 6.3.3
- Keep the argument list distinct from the code block: a block is part of the call syntax, not another argument. section 6.3.3
Method names inside calls
In `string.scan(/[^,]+/)`, `scan` is the method name, `string` is the receiver, and the regular expression is an argument. In `string.scan(/[^,]+/) {|word| puts word }`, the same method name appears with both an argument and a code block. section 6.3.3
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 compact method-call forms to see how the method name remains required while arguments and blocks vary independently. section 6.3.3
