Project

General

Profile

Actions

Bug #9291

closed

array splatting a nil works, but hash splatting a nil does not

Added by rits (First Last) about 10 years ago. Updated about 4 years ago.

Status:
Rejected
Target version:
-
ruby -v:
ruby 2.0.0p353 (2013-11-22 revision 43784) [i686-linux]
Backport:
[ruby-core:59297]

Description

irb(main):001:0> [*nil]
=> []
irb(main):002:0> {**nil}
TypeError: no implicit conversion of nil into Hash


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #8507: Keyword splat does not convert arg to HashRejectedmatz (Yukihiro Matsumoto)Actions

Updated by rits (First Last) about 10 years ago

this could be used like this: method a: 1, **({b: 1} if condition)

Updated by rits (First Last) over 9 years ago

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

Updated by marcandre (Marc-Andre Lafortune) over 9 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?

Updated by mame (Yusuke Endoh) about 4 years ago

  • Status changed from Open to Rejected
  • Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN)

Closing as it is by design. If you want the change, please open a feature request ticket with a use case.

Actions #5

Updated by mame (Yusuke Endoh) about 4 years ago

  • Is duplicate of Bug #8507: Keyword splat does not convert arg to Hash added
Actions

Also available in: Atom PDF

Like0
Like0Like0Like1Like0Like0