Sha256: 7484cf4ca3ba870c0948ab27de2e706c061b908dbacb48a8126301bdae2b3a2b
Contents?: true
Size: 780 Bytes
Versions: 34
Compression:
Stored size: 780 Bytes
Contents
# frozen_string_literal: true class Hash # Returns a hash that includes everything except given keys. # hash = { a: true, b: false, c: nil } # hash.except(:c) # => { a: true, b: false } # hash.except(:a, :b) # => { c: nil } # hash # => { a: true, b: false, c: nil } # # This is useful for limiting a set of parameters to everything but a few known toggles: # @person.update(params[:person].except(:admin)) def except(*keys) slice(*self.keys - keys) end # Removes the given keys from hash and returns it. # hash = { a: true, b: false, c: nil } # hash.except!(:c) # => { a: true, b: false } # hash # => { a: true, b: false } def except!(*keys) keys.each { |key| delete(key) } self end end
Version data entries
34 entries across 32 versions & 7 rubygems