Just do IT

思うは招く

Ruby の merge の挙動

たとえば、こんな2つのハッシュがあるとする。

smart_phones = {
  apple: :iphone,
  google: :pixel,
  samsung: :galaxy,
}

other_smart_phones = {
  huawei: :p30,
  sharpe: :aquos
}

これらのハッシュをがっちゃんこしたい場合、mergeメソッドを使える。

puts smart_phones.merge(other_smart_phones)

#結果
{:apple=>:iphone, :google=>:pixel, :samsung=>:galaxy, :huawei=>:p30, :sharpe=>:aquos}

Hash#merge (Ruby 2.7.0 リファレンスマニュアル)