Sha256: fffa31e597f465ad6c4d00b597e3ba7fb4115f87e5406b0596efb63ee9ced44e

Contents?: true

Size: 794 Bytes

Versions: 1

Compression:

Stored size: 794 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
        self.dup.delete_if { |k,v| !keys.include?(k) }
      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
        self.dup.delete_if { |k,v| keys.include?(v) }
      end unless {}.respond_to?(:except)
      
    end
  end
end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
animoto-1.1.1 ./lib/animoto/support/hash.rb