Sha256: 87433a9e0fb5bf84b5c6c59468b0dcde0abd416779c4509faaf8f772c7b9eb1d

Contents?: true

Size: 650 Bytes

Versions: 3

Compression:

Stored size: 650 Bytes

Contents

# adapted from https://raw.github.com/rails/rails/master/activesupport/lib/active_support/core_ext/hash/keys.rb
class Hash
  def deep_transform_both!(&block)
    keys.each do |key|
      value = delete(key)
      normalized_key = key.to_s.gsub(/\./, "-")
      self[normalized_key] = value.is_a?(Hash) ? value.deep_transform_both!(&block) : yield(value)
    end
    self
  end

  def deep_stringify_keys_and_values!
    exceptable_data_types = [Fixnum, Float, String, Array, Time]
    deep_transform_both! do |element|
      if exceptable_data_types.include?(element.class)
        element
      else
        element.to_s
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yogi_berra-0.2.1 lib/keys.rb
yogi_berra-0.2.0 lib/keys.rb
yogi_berra-0.1.7 lib/keys.rb