Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/patches/hash.rb
Instance Method Summary collapse
- #crush ⇒ Object
-
#deep_symbolize_keys ⇒ Object
Copied from Rails.
- #deep_underscore_keys ⇒ Object
Instance Method Details
#crush ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/patches/hash.rb', line 18 def crush crushed = each_with_object({}) do |(key, value), hash| crushed_value = value.respond_to?(:crush) ? value.crush : value hash[key] = crushed_value unless crushed_value.nil? end crushed unless crushed.empty? end |
#deep_symbolize_keys ⇒ Object
Copied from Rails
5 6 7 |
# File 'lib/patches/hash.rb', line 5 def deep_symbolize_keys deep_transform_keys { |key| key.to_sym rescue key } # rubocop:disable Style/RescueModifier end |
#deep_underscore_keys ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/patches/hash.rb', line 9 def deep_underscore_keys deep_transform_keys do |key| underscored = key.to_s.underscore key.is_a?(Symbol) ? underscored.to_sym : underscored rescue StandardError key end end |