Module: Shoryuken::Helpers::HashUtils
- Defined in:
- lib/shoryuken/helpers/hash_utils.rb
Overview
Utility methods for hash manipulation.
This module provides helper methods for common hash operations that were previously implemented as core class extensions. By using a dedicated helper module, we avoid polluting the global namespace while maintaining the same functionality.
Class Method Summary collapse
-
.deep_symbolize_keys(hash) ⇒ Hash, Object
Recursively converts hash keys to symbols.
Class Method Details
.deep_symbolize_keys(hash) ⇒ Hash, Object
Recursively converts hash keys to symbols.
This method traverses a hash structure and converts all string keys to symbols, including nested hashes. Non-hash values are left unchanged. This is useful for normalizing configuration data loaded from YAML files.
45 46 47 48 49 50 51 52 |
# File 'lib/shoryuken/helpers/hash_utils.rb', line 45 def deep_symbolize_keys(hash) return hash unless hash.is_a?(Hash) hash.each_with_object({}) do |(key, value), result| symbol_key = key.is_a?(String) ? key.to_sym : key result[symbol_key] = value.is_a?(Hash) ? deep_symbolize_keys(value) : value end end |