Suppose a method usually uses 1 for its third argument, but callers sometimes need another value. Ruby lets the parameter declare that fallback: `def default_args(a, b, c=1)`. The first two arguments are required; `c` is optional. section 2.4.1
Omit or override the argument
With `def default_args(a, b, c=1); p a, b, c; end`, calling `default_args(3, 2)` prints `3`, `2`, and `1`. Calling `default_args(4, 5, 6)` prints `4`, `5`, and `6`. The default is assigned to the parameter only when the caller omits that argument. section 2.4.1
A default-valued parameter is one kind of optional parameter. A `*args` parameter is optional too, but it collects extra arguments into an array rather than supplying a declared fallback. In either case, argument binding assigns values to local variables usable within the method. section 2.4.1 section 2.4.3
When a signature mixes parameter types, keep their binding rules in mind:
- Required parameters take priority, including ones to the right of optional parameters. In `def m(a, b=2, *c, d)`, a call with two arguments leaves `b` at `2`, gives `c` an empty array, and binds the final argument to `d`. section 2.4.3
- Do not put a splat parameter before a default-valued parameter: `def broken_args(x, *y, z=1)` is a syntax error. Keep signatures simple when possible. section 2.4.3
Defaults for keyword arguments
Ruby also accepts defaults for named parameters: `def m(a: 1, b: 2); p a, b; end`. Calling `m` uses both defaults; `m(a: 10)` uses `10` for `a` and `2` for `b`. Unlike positional arguments, callers can supply `b` without supplying `a`. section 9.3.8
Do not confuse a parameter default with a hash’s default value. `Hash.new(0)` supplies `0` when a nonexistent key is looked up; it does not declare an optional method parameter or add that key to the hash. section 9.3.3



















