Class: Hash
Overview
Hash Override taken from Rails
Instance Method Summary collapse
- #_deep_transform_keys_in_object(object, &block) ⇒ Object
- #deep_symbolize_keys ⇒ Object
- #deep_transform_keys(&block) ⇒ Object
- #symbolize_keys ⇒ Object
- #transform_keys ⇒ Object
Instance Method Details
#_deep_transform_keys_in_object(object, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/api_ai_wrapper/extensions/hash.rb', line 13 def _deep_transform_keys_in_object(object, &block) case object when Hash object.each_with_object({}) do |(key, value), result| result[yield(key)] = _deep_transform_keys_in_object(value, &block) end when Array object.map {|e| _deep_transform_keys_in_object(e, &block) } else object end end |
#deep_symbolize_keys ⇒ Object
34 35 36 |
# File 'lib/api_ai_wrapper/extensions/hash.rb', line 34 def deep_symbolize_keys deep_transform_keys { |key| key.to_sym rescue key } end |
#deep_transform_keys(&block) ⇒ Object
26 27 28 |
# File 'lib/api_ai_wrapper/extensions/hash.rb', line 26 def deep_transform_keys(&block) _deep_transform_keys_in_object(self, &block) end |
#symbolize_keys ⇒ Object
30 31 32 |
# File 'lib/api_ai_wrapper/extensions/hash.rb', line 30 def symbolize_keys transform_keys { |key| key.to_sym rescue key } end |
#transform_keys ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/api_ai_wrapper/extensions/hash.rb', line 4 def transform_keys return enum_for(:transform_keys) unless block_given? result = self.class.new each_key do |key| result[yield(key)] = self[key] end result end |