Project

General

Profile

Bug #11860

Updated by sawa (Tsuyoshi Sawada) about 5 years ago

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

 ```ruby 
 class String 
   def foo; end 
 end 

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

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

 ```ruby 
 h = {} 

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

Back