Hash#remap
Since we're mapping Array's around, we might as well do Hash's too. (And yes, I actually needed these)
class Hash # remap the keys and/or values of a hash to a new hash def remap(hash={}) each { |k,v| yield hash, k, v } hash end # remap the keys and/or values of a hash to self. Probably wouldn't # do the keys unless providing aliases. def remap!(&block) remap self, &block end end
I just know you had to do this recently:
stuff = {"a"=>5, "b"=>10, "c"=>15} stuff.remap do |h, k, v| h[(k * 2).to_sym] = v * 2 end => {:aa=>10, :bb=>20, :cc=>30}
Spotlight on Ruby
A nifty Spotlight plugin so you can search Ruby code. Via MacOS X Hints
In other news, I just got 186 lines in Tetris! (old-school Gameboy, the only way to play) What's your highest?