Project

General

Profile

Bug #9898

Updated by nobu (Nobuyoshi Nakada) almost 10 years ago

Case 1: If a method takes a single argument, and the method is called with a keyword splat, the method receives the passed object, not the result of calling `#to_hash` #to_hash on the object: 

 ~~~ruby 
 # kw1.rb 
 def m(a) a end 
 o = Object.new 
 def o.to_hash() puts "to_hash"; { a: 1 } end 
 p m(**o) 
 ~~~ 

 ~~~ 
 $ ruby -v kw1.rb 
 ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0] 
 to_hash 
 #<Object:0x007fdee188ab90> 
 ~~~ 

 Would someone please explain why the result of `#to_hash` #to_hash in not passed to the method? 


 Case 2: If the method takes a keyword argument, `#to_hash` #to_hash is called at the send site and at the receiver: 

 ~~~ruby 
 # kw2.rb 
 def mk(a:) a end 
 o = Object.new 
 def o.to_hash() puts "to_hash"; { a: 1 } end 
 p mk(**o) 
 ~~~ 

 ~~~ 
 $ ruby -v kw2.rb 
 ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0] 
 to_hash 
 to_hash 
 1 
 ~~~ 

 Would someone please explain why `#to_hash` #to_hash is called at both the send site and at the receiver? 

Back