Skip to content

Instantly share code, notes, and snippets.

@bxt
Created March 19, 2013 01:11
Show Gist options
  • Save bxt/5192713 to your computer and use it in GitHub Desktop.
Save bxt/5192713 to your computer and use it in GitHub Desktop.
Monkey-patches the methods transform into ruby's Hash class to allow easy mapping of hash values.
class Hash
def transform
inject(self.class.new){|acc, (k, v)| acc[k] = yield(v); acc }
end
def transform!
each{|k,v| self[k]=yield(v)}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment