Sha256: 59f65c2199204531913d73b71035dda7d7a404c9e4ef300b6aefd70e168d2949

Contents?: true

Size: 447 Bytes

Versions: 32

Compression:

Stored size: 447 Bytes

Contents

class Hash
  def depth
    1 + (values.map { |v| v.is_a?(Hash) ? v.depth : 1 }.max)
  end

  def deep_symbolize_keys
    self.each_with_object({}) do |(k, v), h|
      if v.is_a?(Array)
        v = v.map do |vv|
          if vv.is_a?(Hash)
            vv.deep_symbolize_keys
          else
            vv
          end
        end
      elsif v.is_a?(Hash)
        v = v.deep_symbolize_keys
      end

      h[k.to_s.to_sym] = v
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
rundock-0.2.11 lib/rundock/ext/hash.rb
rundock-0.2.10 lib/rundock/ext/hash.rb
rundock-0.2.9 lib/rundock/ext/hash.rb
rundock-0.2.8 lib/rundock/ext/hash.rb
rundock-0.2.7 lib/rundock/ext/hash.rb
rundock-0.2.6 lib/rundock/ext/hash.rb
rundock-0.2.5 lib/rundock/ext/hash.rb
rundock-0.2.4 lib/rundock/ext/hash.rb
rundock-0.2.3 lib/rundock/ext/hash.rb
rundock-0.2.2 lib/rundock/ext/hash.rb
rundock-0.2.0 lib/rundock/ext/hash.rb
rundock-0.1.0 lib/rundock/ext/hash.rb