module Fusu::Hash::Except

Public Instance Methods

except(hash, *keys) click to toggle source

Returns a hash that includes everything but the given keys.

hash = { a: true, b: false, c: nil}
Fusu::Hash.except(hash, :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(Fusu::Hash.except(params[:person], :admin))
# File lib/fusu/hash/except.rb, line 11
def except(hash, *keys)
  except!(hash.dup, *keys)
end
except!(hash, *keys) click to toggle source

Replaces the hash without the given keys.

hash = { a: true, b: false, c: nil}
Fusu::Hash.except!(hash, :c) # => { a: true, b: false}
hash # => { a: true, b: false }
# File lib/fusu/hash/except.rb, line 19
def except!(hash, *keys)
  keys.each { |key| hash.delete(key) }
  hash
end