# coding: utf-8 class Hash def hmap(&block) reduce({}) { |hash, (k, v)| hash.merge(block.call(k, v)) } end def hmap!(&block) replace hmap(&block) end end