neumachen
1/12/2015 - 2:58 PM

hash.rb

class Hash
  def filter
    result = self.map do |k, v|
      r = yield v if block_given?
      [k, r]
    end
    Hash[*result.flatten]
  end
  
  def filter! &block
    replace self.filter &block
  end
end