Sha256: 8c53f9e795bc980bdfbdc8709e81df837013d93420aa001e4a7418548784a4e2

Contents?: true

Size: 731 Bytes

Versions: 23

Compression:

Stored size: 731 Bytes

Contents

module Cms
  module Extensions
    module Hash
      #Returns a copy of the hash without the keys passed as arguments
      def except(*args)
        reject {|k,v| args.include?(k) }
      end
      
      # This takes a list of keys and returns a new hash 
      # containing the key/values that match the keys passed in. 
      # This will also remove the keys from this hash
      #
      # Note: This behavior is slightly different from ActiveSupport Hash#extract! which can add nil keys if they don't exist.
      def extract_only!(*keys)
        keys.inject({}) do |hash, key|
          hash[key] = delete(key) if has_key?(key)
          hash
        end
      end
    end
  end
end
Hash.send(:include, Cms::Extensions::Hash)

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
browsercms-3.5.7 lib/cms/extensions/hash.rb
browsercms-3.5.6 lib/cms/extensions/hash.rb
browsercms-3.5.5 lib/cms/extensions/hash.rb
browsercms-3.5.4 lib/cms/extensions/hash.rb
browsercms-3.5.3 lib/cms/extensions/hash.rb
browsercms-3.5.2 lib/cms/extensions/hash.rb
browsercms-3.5.1 lib/cms/extensions/hash.rb
browsercms-3.5.0 lib/cms/extensions/hash.rb
browsercms-3.5.0.rc3 lib/cms/extensions/hash.rb
browsercms-3.5.0.rc2 lib/cms/extensions/hash.rb
browsercms-3.5.0.rc1 lib/cms/extensions/hash.rb
browsercms-3.4.2 lib/cms/extensions/hash.rb
browsercms-3.3.4 lib/cms/extensions/hash.rb
browsercms-3.4.2.rc1 lib/cms/extensions/hash.rb
browsercms-3.4.1 lib/cms/extensions/hash.rb
browsercms-3.4.0 lib/cms/extensions/hash.rb
browsercms-3.4.0.rc2 lib/cms/extensions/hash.rb
browsercms-3.4.0.rc1 lib/cms/extensions/hash.rb
browsercms-3.3.3 lib/cms/extensions/hash.rb
browsercms-3.3.2 lib/cms/extensions/hash.rb