Class: TaintedParams::StringKeyHash

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/tainted_params/string_key_hash.rb

Overview

< SimpleDelegator

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ StringKeyHash

Returns a new instance of StringKeyHash.

Raises:

  • (ArgumentError)


15
16
17
18
# File 'lib/tainted_params/string_key_hash.rb', line 15

def initialize(hash)
  raise ArgumentError unless hash.is_a?(Hash)
  @hash = self.class.stringify_keys(hash).freeze
end

Class Method Details

.stringify_keys(hash) ⇒ Object



9
10
11
12
13
# File 'lib/tainted_params/string_key_hash.rb', line 9

def self.stringify_keys(hash)
  hash.map_pairs{ |k,v|
    [k.to_s, v]
  }
end

Instance Method Details

#[](key) ⇒ Object



22
23
24
# File 'lib/tainted_params/string_key_hash.rb', line 22

def [](key)
  @hash[convert_key(key)]
end

#dupObject



30
31
32
# File 'lib/tainted_params/string_key_hash.rb', line 30

def dup
  self.class.new(self)
end

#merge(hash, &block) ⇒ Object



26
27
28
# File 'lib/tainted_params/string_key_hash.rb', line 26

def merge(hash, &block)
  self.class.new(self.to_hash.merge(hash, &block))
end

#to_hashObject



34
35
36
# File 'lib/tainted_params/string_key_hash.rb', line 34

def to_hash
  @hash
end