class SafeCookies::Util

Public Class Methods

except!(hash, *rejected_keys) click to toggle source

rejected_keys may be of type String or Regex

# File lib/safe_cookies/util.rb, line 15
def except!(hash, *rejected_keys)
  hash.delete_if do |key, _value|
    rejected_keys.any? { |rejected| rejected === key }
  end
end
slice(hash, *allowed_keys) click to toggle source
# File lib/safe_cookies/util.rb, line 4
def slice(hash, *allowed_keys)
  sliced_hash = hash.select { |key, _value|
    allowed_keys.include? key
  }

  # Normalize the result of Hash#select
  # (Ruby 1.8 returns an Array, Ruby 1.9 returns a Hash)
  Hash[sliced_hash]
end