Skip to content

Instantly share code, notes, and snippets.

@lukaszkorecki
Created February 16, 2015 10:35
Show Gist options
  • Save lukaszkorecki/5073142d41b4231d2588 to your computer and use it in GitHub Desktop.
Save lukaszkorecki/5073142d41b4231d2588 to your computer and use it in GitHub Desktop.
ha = {
a: 1,
b: 2,
c: 3
}
# With default.
s = [:a, :d, :c].map { |k| { k => ha.fetch(k, -1) } }.reduce(&:merge!)
puts ha
puts s
# Throw if no defaults
[:a, :d, :c].map { |k| { k => ha.fetch(k) } }.reduce(&:merge!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment