x = {:name => "John", :data => {:physical => {:age => 25, :weight => 150}}}
I’m looking to move the subattributes of data up one level (but not necessarily simply flatten all attributes). In this case, I essentially want to move the :physical attribute “up” one level.
I’m trying this
y = x[:data']
y.each{ |key| x[key] = y[key] }
but I get …
x = x.except(:data)
=> {:name=>"John", [:physical, {:age=>25, :weight=>150}]=>nil}
I’m looking for …
=> {:name=>"John", :physical => {:age=>25, :weight=>150}}
Try this: