Hacker News new | ask | show | jobs
by kazinator 536 days ago
Does that work due to Ruby having Python-like broken semantics for evaluating the default value expressions for optional arguments? (I have no idea.) Or does it work due to the object denoted by {...} being a real literal?

If the default value expression is evaluated on each call to the function in which it is required rather than at function definition time, and if the { ... } syntax is a constructor that creates a fresh object, then this wouldn't work; one of those two conditions (or both) must be broken.

1 comments

Python's default argument is evaluated once. It's very sibtle behavior that is inlile Ruby.