Invoking a Method

     <receiver.>name < arguments > < {block} >      <receiver::>name < arguments > < {block} > arguments ( <arg>* <, hashlist> <*array> <&a_proc> ) block { blockbody } or do blockbody end

When invoking a method, the parentheses around the arguments may be omitted if the expression is otherwise unambiguous. So, foo 3, 4 as a line by itself is a legal call to foo with two arguments. Usually, the ambiguity happens if there are method calls in the arguments. If you had both foo and bar as methods, then foo 3, bar 4, 5 would trigger an error because the parser would attempt to resolve bar 4 as the second argument to foo. Fully parenthesizing as foo(3, bar(4, 5)) is preferred, but foo 3, (bar 4, 5) would also be legal.

Get Programming Ruby 3.3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.