Class: Mashed::StringyHash
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Mashed::StringyHash
- Defined in:
- lib/mashed/stringy_hash.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object (also: #store)
- #delete(key, &blk) ⇒ Object
- #key?(key) ⇒ Boolean
- #merge(other_hash, &blk) ⇒ Object
- #merge!(other_hash, &blk) ⇒ Object
- #replace(other_hash, &blk) ⇒ Object
- #stringify ⇒ Object
- #update(other_hash, &blk) ⇒ Object
Class Method Details
.stringify(object) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/mashed/stringy_hash.rb', line 5 def self.stringify(object) if object.is_a?(Array) object.map { |value| StringyHash.stringify(value) } elsif object.is_a?(Hash) StringyHash.new(object.each_with_object({}) do |(k,v), h| h[k.to_s] = StringyHash.stringify(v) end) else object end end |
Instance Method Details
#[](key) ⇒ Object
21 22 23 |
# File 'lib/mashed/stringy_hash.rb', line 21 def [](key) super(key.to_s) end |
#[]=(key, value) ⇒ Object Also known as: store
25 26 27 |
# File 'lib/mashed/stringy_hash.rb', line 25 def []=(key, value) super(key.to_s, value) end |
#delete(key, &blk) ⇒ Object
34 35 36 |
# File 'lib/mashed/stringy_hash.rb', line 34 def delete(key, &blk) super(key.to_s, &blk) end |
#key?(key) ⇒ Boolean
30 31 32 |
# File 'lib/mashed/stringy_hash.rb', line 30 def key?(key) super(key.to_s) end |
#merge(other_hash, &blk) ⇒ Object
38 39 40 |
# File 'lib/mashed/stringy_hash.rb', line 38 def merge(other_hash, &blk) super(self.class.stringify(other_hash), &blk) end |
#merge!(other_hash, &blk) ⇒ Object
42 43 44 |
# File 'lib/mashed/stringy_hash.rb', line 42 def merge!(other_hash, &blk) super(self.class.stringify(other_hash), &blk) end |
#replace(other_hash, &blk) ⇒ Object
46 47 48 |
# File 'lib/mashed/stringy_hash.rb', line 46 def replace(other_hash, &blk) super(self.class.stringify(other_hash), &blk) end |
#stringify ⇒ Object
17 18 19 |
# File 'lib/mashed/stringy_hash.rb', line 17 def stringify dup end |
#update(other_hash, &blk) ⇒ Object
50 51 52 |
# File 'lib/mashed/stringy_hash.rb', line 50 def update(other_hash, &blk) super(self.class.stringify(other_hash), &blk) end |