Feature #21047
openChange `*nil` to not call `nil.to_a`, for consistency with `**nil`
Description
In Ruby 3.3, we started accepting **nil
for keyword splats. This does not call nil.to_hash
, unlike other uses of **
for splatting. This made **nil
handling inconsistent with *nil
handling, as *nil
historically has called nil.to_a
. I propose we make them consistent, by having *nil
not call nil.to_a
.
Advantage: In addition to more consistent behavior with **nil
, making *nil
not call nil.to_a
opens up new a optimization opportunity, since it allows *nil
to be optimized to not allocate an array, similar to how **nil
is already optimized to not allocate a hash.
Disadvantage: Minor backwards compatibility breakage, though it is very unlikely any code other than test code will break, because overriding nil.to_a
to return anything other than the empty array would likely break any large Ruby application.
I've submitted a pull request to implement this: https://github.com/ruby/ruby/pull/12597
Updated by matz (Yukihiro Matsumoto) 1 day ago
Accepted.
Matz.