Skip to content

@apeiros /hash_map.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Implement Hash#map_keys, #map_keys!, #map_values, #map_values!, #map_pairs and #map_pairs!
class Hash
def map_keys
map_pairs { |key, value| [yield(key), value] }
end
def map_keys!
map_pairs! { |key, value| [yield(key), value] }
end
def map_values
map_pairs { |key, value| [key, yield(value)] }
end
def map_values!
map_pairs! { |key, value| [key, yield(value)] }
end
def map_pairs(&block)
Hash[map(&block)]
end
def map_pairs!(&block)
replace(map_pairs(&block))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.