2.4. A close look at method arguments

Methods you write in Ruby can take zero or more arguments. They can also allow a variable number of arguments. We’ll examine argument semantics in several different ways in this section:

  • The difference between required and optional arguments
  • How to assign default values to arguments
  • The rules governing the order in which you have to arrange the parameters in the method signature so that Ruby can make sense of argument lists in method calls and bind the parameters correctly
  • What you can’t do with arguments in Ruby

Table 2.2 will summarize these at the end of this section.

Note

There’s more to argument list semantics than we’ll cover here. Specifically, there’s such a thing in Ruby as keyword arguments ...

Get The Well-Grounded Rubyist, Second Edition 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.