Project

General

Profile

Actions

Bug #11860

closed
Image

Double splat does not work on empty hash assigned via variable

Bug #11860: Double splat does not work on empty hash assigned via variable

Added by sawa (Tsuyoshi Sawada) over 10 years ago. Updated almost 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
2.3.0preview2 (2015-12-11 trunk 53028) [x86_64-linux]
[ruby-core:72429]

Description

When an empty hash is given as a literal, the double splat operates on it, and leaves nothing, which is expected.

class String
  def foo; end
end

[**{}] # => []
"foo".foo(**{}) # => nil
"foo".send("foo", **{}) # => nil

However, when an empty hash is given via variable, the double splat retains an empty hash in place.

h = {}

[**h] # => [{}]
"foo".foo(**h) # => wrong number of arguments (given 1, expected 0)
"foo".send("foo", **h) # => wrong number of arguments (given 1, expected 0)

Related issues 1 (0 open1 closed)

Related to Ruby - Feature #14183: "Real" keyword argumentClosedActions

Image Updated by sawa (Tsuyoshi Sawada) over 10 years ago Actions #1 [ruby-core:72431]

I found more cases (other than via variable) that the double splat does not work on an empty hash. While parenthesis or nesting does not cause the issue:

[**({})] # => []
[**begin {} end] # => []
[**{**{}}] # => []

more complicated expressions seem to cause the issue:

[**({} if true)] # => [{}]
[**(if true; {} end)] # => [{}]
[**(false ? :foo : {})] # => [{}]

Image Updated by justcolin (Colin Fulton) over 10 years ago Actions #2 [ruby-core:73811]

A similar bug happens when using the double splat operator in the parameter list of a method definition. See #12022.

Image Updated by sawa (Tsuyoshi Sawada) over 10 years ago Actions #3 [ruby-core:74216]

This bug is related to #10708.

Image Updated by nobu (Nobuyoshi Nakada) about 10 years ago Actions #4 [ruby-core:75553]

  • Description updated (diff)

Image Updated by sawa (Tsuyoshi Sawada) about 7 years ago Actions #5

  • Description updated (diff)

Image Updated by jeremyevans0 (Jeremy Evans) almost 7 years ago Actions #6

Image Updated by jeremyevans0 (Jeremy Evans) almost 7 years ago Actions #7 [ruby-core:94746]

  • Status changed from Open to Closed

With recent commits to the master branch, keyword splats of empty hashes do not pass positional arguments to methods or cause an empty hash to be added to an array.

Actions

Also available in: PDF Atom