Sha256: 3f57a0f4fa309f50d862c05c89c2e080c73edafc85b6a5beef139613fbe4a31b

Contents?: true

Size: 818 Bytes

Versions: 27

Compression:

Stored size: 818 Bytes

Contents

module CoreExt
  module Hash



    def pick(*picks)
      picks = picks.flatten

      mapped_picks = {}
      picks.each do |pick|
        if pick.is_a?(Hash)
          mapped_picks.merge!(pick)
        else
          mapped_picks[pick] = pick
        end
      end

      mapped_picks.inject({}) do |result, (key, new_key)|
        result[new_key] = self[key] if self.key?(key)
        result
      end
    end



    def pick!(*picks)
      picks = picks.flatten
      keys.each {|key| self.delete(key) unless picks.member?(key) }
    end



    def except(*picks)
      result = self.dup
      result.except!(*picks)
      result
    end



    def except!(*picks)
      picks = picks.flatten
      keys.each {|key| self.delete(key) if picks.member?(key) }
    end



  end
end

Hash.send :include, CoreExt::Hash

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
houston-core-0.9.2 lib/core_ext/hash.rb
houston-core-0.9.1 lib/core_ext/hash.rb
houston-core-0.9.0 lib/core_ext/hash.rb
houston-core-0.9.0.rc1 lib/core_ext/hash.rb
houston-core-0.8.4 lib/core_ext/hash.rb
houston-core-0.8.3 lib/core_ext/hash.rb
houston-core-0.8.2 lib/core_ext/hash.rb
houston-core-0.8.1 lib/core_ext/hash.rb
houston-core-0.8.0 lib/core_ext/hash.rb
houston-core-0.8.0.pre2 lib/core_ext/hash.rb
houston-core-0.8.0.pre lib/core_ext/hash.rb
houston-core-0.7.0 lib/core_ext/hash.rb
houston-core-0.7.0.beta4 lib/core_ext/hash.rb
houston-core-0.7.0.beta3 lib/core_ext/hash.rb
houston-core-0.7.0.beta2 lib/core_ext/hash.rb
houston-core-0.7.0.beta lib/core_ext/hash.rb
houston-core-0.6.3 lib/core_ext/hash.rb
houston-core-0.6.2 lib/core_ext/hash.rb
houston-core-0.6.1 lib/core_ext/hash.rb
houston-core-0.6.0 lib/core_ext/hash.rb