Sha256: 0c9b2f616e634938e740ce8fa46124c94fd5057d434518313bcbbf2b2f4d8e6f

Contents?: true

Size: 836 Bytes

Versions: 10

Compression:

Stored size: 836 Bytes

Contents

module Animoto
  module Support
    module Hash
      
      # Returns a new hash with only the listed keys from this hash.
      #
      # @param [Array<Object>] keys the keys to include
      # @return [Hash{Object=>Object}] a new hash with only the listed keys
      def only *keys
        inject({}) { |h,(k,v)| h.merge(keys.include?(k) ? {k => v} : {}) }
      end unless {}.respond_to?(:only)
      
      # Returns a new hash with all keys from this hash except the listed ones.
      #
      # @param [Array<Object>] keys the keys to exclude
      # @return [Hash{Object=>Object}] a new hash without the listed keys
      def except *keys
        inject({}) { |h,(k,v)| h.merge(!keys.include?(v) ? {k => v} : {}) }
      end unless {}.respond_to?(:except)
      
    end
  end
end

Hash.__send__ :include, Animoto::Support::Hash

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
animoto-1.5.6 ./lib/animoto/support/hash.rb
animoto-1.5.5 ./lib/animoto/support/hash.rb
animoto-1.5.4 ./lib/animoto/support/hash.rb
animoto-1.5.3 ./lib/animoto/support/hash.rb
animoto-1.5.2 ./lib/animoto/support/hash.rb
animoto-1.5.1 ./lib/animoto/support/hash.rb
animoto-1.5.0 ./lib/animoto/support/hash.rb
animoto-1.3.1 ./lib/animoto/support/hash.rb
animoto-1.3.0 ./lib/animoto/support/hash.rb
animoto-1.2.0 ./lib/animoto/support/hash.rb