functions/chained_defaults_parens.rb
tests/_examples/functions/chained_defaults_parens.rb in the metorex repository.
# One default may set several parameters at once, and a later parameter reads
# what an earlier one was given.
def shared(a = b = c = {})
[a, b, c]
end
p(shared)
p(shared(1))
def widened(first = 2, second = first * 3)
[first, second]
end
p(widened)
p(widened(5))
Output:
[{}, {}, {}]
[1, nil, nil]
[2, 6]
[5, 15]