Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created February 13, 2018 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/ab7336fcef83e5f9dd2f7f3788295780 to your computer and use it in GitHub Desktop.
Save havenwood/ab7336fcef83e5f9dd2f7f3788295780 to your computer and use it in GitHub Desktop.
An Example Implementation of Hash#fetch_slice
class Hash
def fetch_slice(*keys, &block)
keys.zip(fetch_values(*keys, &block)).to_h
end
end
hsh = {a: 1, b: 2}
hsh.fetch_slice(:a, :d) { nil }
#=> {:a=>1, :d=>nil}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment