Module: Buff::Extensions::Hash::Except

Included in:
Hash
Defined in:
lib/buff/extensions/hash/except.rb

Overview

Instance Method Summary collapse

Instance Method Details

#except(*keys) ⇒ Object

Return a hash that includes everything but the given keys. This is useful for limiting a set of parameters to everything but a few known toggles:

@person.update(params[:person].except(:admin))


10
11
12
# File 'lib/buff/extensions/hash/except.rb', line 10

def except(*keys)
  dup.except!(*keys)
end

#except!(*keys) ⇒ Object

Replaces the hash without the given keys.



15
16
17
18
# File 'lib/buff/extensions/hash/except.rb', line 15

def except!(*keys)
  keys.each { |key| delete(key) }
  self
end