Class: SafeCookies::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/safe_cookies/util.rb

Class Method Summary collapse

Class Method Details

.except!(hash, *rejected_keys) ⇒ Object

rejected_keys may be of type String or Regex



15
16
17
18
19
# 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) ⇒ Object



4
5
6
7
8
9
10
11
12
# 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