Project

General

Profile

Bug #12027

Updated by nobu (Nobuyoshi Nakada) over 4 years ago

I'm not sure it is not intended, but feels really strange: 

 ~~~ruby ~~~ 
 class A 
   def to_hash 
     {foo: 'bar'} 
   end 
 end 

 class B < Hash 
   def to_hash 
     {foo: 'bar'} 
   end 
 end 

 a = A.new 
 b = B.new 

 p({**a}) # => {foo: 'bar'} 
 p({**b}) # => {} -- ooops. Seems "internal" hash state is used 
 # therefore: 
 b['test'] = 1 
 p({**b}) # => wrong argument type String (expected Symbol) (TypeError) 
 ~~~ 

 What am I missing here?

Back