Bug #9291
array splatting a nil works, but hash splatting a nil does not
Description
irb(main):001:0> [nil]
=> []
irb(main):002:0> {*nil}
TypeError: no implicit conversion of nil into Hash
History
Updated by rits (First Last) almost 6 years ago
this could be used like this: method a: 1, **({b: 1} if condition)
Updated by rits (First Last) over 5 years ago
So is there a reason * and ** should work differently for nil?
Updated by marcandre (Marc-Andre Lafortune) over 5 years ago
- Assignee set to matz (Yukihiro Matsumoto)
Currently, *
uses explicit conversion to array (to_a
, not to_ary
), while **
uses implicit conversion to hash (to_hash
, not to_h
).
So your question about nil
can be explained this way, since nil.to_a #=> []
but nil.to_hash
is not defined.
The real question is then: shouldn't **
be using explicit conversion to hash with to_h?