Class: Crystal::HashWithStringifyKeys
- Inherits:
-
Hash
- Object
- Hash
- Crystal::HashWithStringifyKeys
- Defined in:
- lib/crystal/hash_with_stringify_keys.rb
Instance Method Summary collapse
-
#initialize(constructor = {}) ⇒ HashWithStringifyKeys
constructor
A new instance of HashWithStringifyKeys.
-
#stringify_keys ⇒ Object
Return a new hash with all keys converted to strings.
-
#stringify_keys! ⇒ Object
Convert all keys in the hash to strings.
Constructor Details
#initialize(constructor = {}) ⇒ HashWithStringifyKeys
Returns a new instance of HashWithStringifyKeys.
3 4 5 6 7 8 9 10 |
# File 'lib/crystal/hash_with_stringify_keys.rb', line 3 def initialize(constructor = {}) if constructor.is_a?(Hash) super() update(constructor).stringify_keys! else super(constructor) end end |
Instance Method Details
#stringify_keys ⇒ Object
Return a new hash with all keys converted to strings.
29 30 31 |
# File 'lib/crystal/hash_with_stringify_keys.rb', line 29 def stringify_keys dup.stringify_keys! end |
#stringify_keys! ⇒ Object
Convert all keys in the hash to strings.
19 20 21 22 23 24 25 |
# File 'lib/crystal/hash_with_stringify_keys.rb', line 19 def stringify_keys! keys.each do |k| stringify_keys_recursively!(self[k]) self[k.to_s] = self.delete(k) end self end |