Created
February 13, 2018 18:34
-
-
Save havenwood/ab7336fcef83e5f9dd2f7f3788295780 to your computer and use it in GitHub Desktop.
An Example Implementation of Hash#fetch_slice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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