Sha256: 582b8828038a60baeff67e08d3da759a834c299634bcbd70fa44a04509cc0152

Contents?: true

Size: 516 Bytes

Versions: 8

Compression:

Stored size: 516 Bytes

Contents

class Hash

  # Returns a new hash less the given keys.
  def except(*less_keys)
    hash = dup
    less_keys.each{ |k| hash.delete(k) }
    hash
  end

  # Replaces hash with new hash less the given keys.
  # This returns the hash of keys removed.
  #
  #   h = {:a=>1, :b=>2, :c=>3}
  #   h.except!(:a)  #=> {:a=>1}
  #   h              #=> {:b=>2,:c=>3}
  #
  # Returns a Hash of the removed pairs.
  def except!(*rejected)
    removed = {}
    rejected.each{ |k| removed[k] = delete(k) }
    removed
  end

end

Version data entries

8 entries across 7 versions & 1 rubygems

Version Path
facets-3.0.0 lib/core/facets/hash/except.rb
facets-2.9.3 lib/core/facets/hash/except.rb
facets-2.9.2 lib/core/facets/hash/except.rb
facets-2.9.2 src/core/facets/hash/except.rb
facets-2.9.1 lib/core/facets/hash/except.rb
facets-2.9.0 lib/core/facets/hash/except.rb
facets-2.9.0.pre.2 lib/core/facets/hash/except.rb
facets-2.9.0.pre.1 lib/core/facets/hash/except.rb