Module: Tins::HashSymbolizeKeysRecursive
- Includes:
- DeepTransform
- Defined in:
- lib/tins/hash_symbolize_keys_recursive.rb
Overview
This module provides deep symbolization of hash keys. It handles nested structures including hashes and arrays, utilizing an iterative engine to prevent stack overflows and handle circular references.
Instance Method Summary collapse
-
#stringify_keys_recursive(circular: nil) ⇒ Hash
Deeply converts all keys in the hash (and nested hashes) to strings, using an iterative approach to avoid SystemStackError.
-
#stringify_keys_recursive!(circular: nil) ⇒ Hash
Deeply converts all keys in the hash (and nested hashes) to strings in place, using an iterative approach.
-
#symbolize_keys_recursive(circular: nil) ⇒ Hash, ...
Deeply converts all string keys in a hash (and nested hashes/arrays) to symbols using an iterative approach to avoid SystemStackError.
-
#symbolize_keys_recursive!(circular: nil) ⇒ Hash, ...
Deeply converts all string keys in a hash (and nested hashes/arrays) to symbols using an iterative approach.
Methods included from DeepTransform
#_transform_iterative, #deep_transform
Instance Method Details
#stringify_keys_recursive(circular: nil) ⇒ Hash
Deeply converts all keys in the hash (and nested hashes) to strings, using an iterative approach to avoid SystemStackError.
61 62 63 |
# File 'lib/tins/hash_symbolize_keys_recursive.rb', line 61 def stringify_keys_recursive(circular: nil) deep_transform(key: -> x { x.to_s }, circular: circular) end |
#stringify_keys_recursive!(circular: nil) ⇒ Hash
Deeply converts all keys in the hash (and nested hashes) to strings in place, using an iterative approach.
92 93 94 |
# File 'lib/tins/hash_symbolize_keys_recursive.rb', line 92 def stringify_keys_recursive!(circular: nil) replace stringify_keys_recursive(circular: circular) end |
#symbolize_keys_recursive(circular: nil) ⇒ Hash, ...
Deeply converts all string keys in a hash (and nested hashes/arrays) to symbols using an iterative approach to avoid SystemStackError. This method does not modify the original hash.
47 48 49 |
# File 'lib/tins/hash_symbolize_keys_recursive.rb', line 47 def symbolize_keys_recursive(circular: nil) deep_transform(key: -> x { x.to_sym }, circular: circular) end |
#symbolize_keys_recursive!(circular: nil) ⇒ Hash, ...
Deeply converts all string keys in a hash (and nested hashes/arrays) to symbols using an iterative approach. This method modifies the original hash in place.
78 79 80 |
# File 'lib/tins/hash_symbolize_keys_recursive.rb', line 78 def symbolize_keys_recursive!(circular: nil) replace symbolize_keys_recursive(circular: circular) end |