Module: Buff::Extensions::Hash::Except
- Included in:
- Hash
- Defined in:
- lib/buff/extensions/hash/except.rb
Overview
Borrowd and modified from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/except.rb
Instance Method Summary collapse
-
#except(*keys) ⇒ Object
Return a hash that includes everything but the given keys.
-
#except!(*keys) ⇒ Object
Replaces the hash without the given keys.
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 |