Skip to content

Instantly share code, notes, and snippets.

class Hash
def map_values
h = {}; self.each_pair { |k,v| h[k] = yield(v) }; h
end
end
[ 'asdf', 'qwer' ].map{ |val| val * 2 }
# => [ 'asdfasdf', 'qwerqwer' ]
{ :one => 'asdf', :two => 'qwer' }.map{ |val| val * 2 }