Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/docker/rails/ext/hash.rb
Instance Method Summary collapse
-
#except(*keys) ⇒ Object
Returns 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
Returns a hash that includes everything but the given keys.
hash = { a: true, b: false, c: nil}
hash.except(:c) # => { a: true, b: false}
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))
9 10 11 |
# File 'lib/docker/rails/ext/hash.rb', line 9 def except(*keys) dup.except!(*keys) end |
#except!(*keys) ⇒ Object
Replaces the hash without the given keys.
hash = { a: true, b: false, c: nil}
hash.except!(:c) # => { a: true, b: false}
hash # => { a: true, b: false }
17 18 19 20 |
# File 'lib/docker/rails/ext/hash.rb', line 17 def except!(*keys) keys.each { |key| delete(key) } self end |