ruby: Default argument values evaluate each time

Tags: til ruby

When you define a default value for a ruby argument, that expression is evaluated each time the method is invoked and it has access to all the previously define arguments.

def foo(a, b, c=a+b>0)
  ...
end

(This is something I forget each time I come back to ruby.)

Published on: 27 May 2025