多次元hashのマージ
mergeの代わりにdeep_margeを使わないと2階層目以降ˆˆのキーバリューが消滅する
code:ruby
h1 = { a: true, b: { c: 1, 2, 3 } }
h2 = { a: false, b: { x: 3, 4, 5 } }
h1.merge(h2) # => { a: false, b: { x: 3, 4, 5 } }
h1.deep_merge(h2) # => { a: false, b: { c: 1, 2, 3, x: 3, 4, 5 } }
deep_merge (Hash) - APIdock
#Ruby #Rails