Forum: Ruby-core [ruby-trunk - Bug #9291][Open] array splatting a nil works, but hash splatting a nil does not

C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 rits (First Last) (Guest)
on 2013-12-24 11:17
(Received via mailing list)
Issue #9291 has been reported by rits (First Last).

----------------------------------------
Bug #9291: array splatting a nil works, but hash splatting a nil does
not
https://bugs.ruby-lang.org/issues/9291

Author: rits (First Last)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p353 (2013-11-22 revision 43784) [i686-linux]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN


irb(main):001:0> [*nil]
=> []
irb(main):002:0> {**nil}
TypeError: no implicit conversion of nil into Hash
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 rits (First Last) (Guest)
on 2013-12-27 18:50
(Received via mailing list)
Issue #9291 has been updated by rits (First Last).


this could be used like this: method a: 1, **({b: 1} if condition)
----------------------------------------
Bug #9291: array splatting a nil works, but hash splatting a nil does
not
https://bugs.ruby-lang.org/issues/9291#change-43921

Author: rits (First Last)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p353 (2013-11-22 revision 43784) [i686-linux]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN


irb(main):001:0> [*nil]
=> []
irb(main):002:0> {**nil}
TypeError: no implicit conversion of nil into Hash
88144e3f7b9d7e3435a41492887b3999?d=identicon&s=25 Mean Login (mean_l)
on 2014-08-04 16:49
(Received via mailing list)
Issue #9291 has been updated by First Last.


So is there a reason * and ** should work differently for nil?


----------------------------------------
Bug #9291: array splatting a nil works, but hash splatting a nil does
not
https://bugs.ruby-lang.org/issues/9291#change-48192

* Author: First Last
* Status: Open
* Priority: Normal
* Assignee:
* Category:
* Target version:
* ruby -v: ruby 2.0.0p353 (2013-11-22 revision 43784) [i686-linux]
* Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN
0e610136db92027148906c92d57fdb36?d=identicon&s=25 unknown (Guest)
on 2014-08-11 11:43
(Received via mailing list)
Issue #9291 has been updated by Marc-Andre Lafortune.

Assignee set to 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?

----------------------------------------
Bug #9291: array splatting a nil works, but hash splatting a nil does
not
https://bugs.ruby-lang.org/issues/9291#change-48279

* Author: First Last
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* Category:
* Target version:
* ruby -v: ruby 2.0.0p353 (2013-11-22 revision 43784) [i686-linux]
* Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN
This topic is locked and can not be replied to.