Sha256: 4ed1ee07b58c6230e6977d11346c718969f5da6a4b3c38525a811176956808d2

Contents?: true

Size: 786 Bytes

Versions: 1

Compression:

Stored size: 786 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.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.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.0 ./lib/animoto/support/hash.rb