Skip to content

Instantly share code, notes, and snippets.

@kachick
Created December 29, 2016 08:58
Show Gist options
  • Save kachick/34be36415d7d2fda961152bea56e3655 to your computer and use it in GitHub Desktop.
Save kachick/34be36415d7d2fda961152bea56e3655 to your computer and use it in GitHub Desktop.
ruby で hash の splat merge (っていうのか知らないけど) する時は 2.2 からにしといた方が無難

キーワード引数対応あたりから、 ruby でも hash の splat で merge 出来るようになってたのをすっかり見落としてた。 でも https://bugs.ruby-lang.org/issues/10315 が気になるので、使う時は 2.2 からにしといた方が良さそう(最近古いの触らないけど)

ruby -e 'h1={a: 1, b: 1, c: 1}; h2={b: 2, c: 2, d: 2}; p({ **h1, **h2, a: 3 })'

on ruby 2.1.8p440 (2015-12-16 revision 53160) [x86_64-darwin16.0]

{:a=>3, :b=>1, :c=>1, :d=>2}

on ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin16]

{:a=>3, :b=>2, :c=>2, :d=>2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment