Skip to content

Instantly share code, notes, and snippets.

@moklett
Last active October 4, 2017 16:18
Show Gist options
  • Save moklett/a123b1b8853d01aa1c01411a465a7b30 to your computer and use it in GitHub Desktop.
Save moklett/a123b1b8853d01aa1c01411a465a7b30 to your computer and use it in GitHub Desktop.
Ruby Double Splat is a bit like Javascript Spread
a = { a: "a" }
b = { b: "b" }
{ **a, **b }
#=> {:a=>"a", :b=>"b"}
{ z: "z", **a, **b }
#=> {:z=>"z", :a=>"a", :b=>"b"}
{ a: "AAA", **a, **b }
#=> {:a=>"a", :b=>"b"}
{ **a, **b, a: "AAA" }
#=> {:a=>"AAA", :b=>"b"}
# Compare to how I may have done merges before...
merged1 = a.merge(b)
merged2 = { **a, **b }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment