Class: TaintedParams::StringKeyHash
- Inherits:
-
Object
- Object
- TaintedParams::StringKeyHash
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/tainted_params/string_key_hash.rb
Overview
< SimpleDelegator
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #dup ⇒ Object
-
#initialize(hash) ⇒ StringKeyHash
constructor
A new instance of StringKeyHash.
- #key?(k) ⇒ Boolean (also: #include?, #has_key?, #member?)
- #merge(hash, &block) ⇒ Object
- #to_hash ⇒ Object
- #values_at(*args) ⇒ Object
Constructor Details
#initialize(hash) ⇒ StringKeyHash
Returns a new instance of StringKeyHash.
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
#==(other) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/tainted_params/string_key_hash.rb', line 55 def ==(other) case other when Hash then self == self.class.new(other) when self.class then to_hash == other.to_hash else false end end |
#[](key) ⇒ Object
35 36 37 |
# File 'lib/tainted_params/string_key_hash.rb', line 35 def [](key) @hash[convert_key(key)] end |
#dup ⇒ Object
47 48 49 |
# File 'lib/tainted_params/string_key_hash.rb', line 47 def dup self.class.new(self) end |
#key?(k) ⇒ Boolean Also known as: include?, has_key?, member?
27 28 29 |
# File 'lib/tainted_params/string_key_hash.rb', line 27 def key?(k) @hash.key?(convert_key(k)) end |
#merge(hash, &block) ⇒ Object
43 44 45 |
# File 'lib/tainted_params/string_key_hash.rb', line 43 def merge(hash, &block) self.class.new(self.to_hash.merge(hash, &block)) end |
#to_hash ⇒ Object
51 52 53 |
# File 'lib/tainted_params/string_key_hash.rb', line 51 def to_hash @hash end |
#values_at(*args) ⇒ Object
39 40 41 |
# File 'lib/tainted_params/string_key_hash.rb', line 39 def values_at(*args) args.map{ |k| self[k] } end |