Sha256: 8710675734282b5b1f0b42440b273c788d339751a92cc2cf70e6e71079999965

Contents?: true

Size: 546 Bytes

Versions: 37

Compression:

Stored size: 546 Bytes

Contents

class Hash
  
  # A depth-first look to find the deepest point in the Hash. 
  # The top level Hash is counted in the total so the final
  # number is the depth of its children + 1. An example:
  # 
  #     ahash = { :level1 => { :level2 => {} } }
  #     ahash.deepest_point  # => 3
  #
  def deepest_point(h=self, steps=0)
    if h.is_a?(Hash)
      steps += 1
      h.each_pair do |n,possible_h|
        ret = deepest_point(possible_h, steps)
        steps = ret if steps < ret
      end
    else
      return 0
    end
    steps
  end

end

Version data entries

37 entries across 37 versions & 5 rubygems

Version Path
tryouts-0.6.0 lib/tryouts/mixins/hash.rb
tryouts-0.6.1 lib/tryouts/mixins/hash.rb
rudy-0.7.0 lib/rudy/mixins/hash.rb
rudy-0.7.3 lib/rudy/mixins/hash.rb
rudy-0.7.4 lib/rudy/mixins/hash.rb
rudy-0.7.6 lib/rudy/mixins/hash.rb
rudy-0.7.1 lib/rudy/mixins/hash.rb
rudy-0.8.1 lib/rudy/mixins/hash.rb
rudy-0.8.2 lib/rudy/mixins/hash.rb
rudy-0.8.0 lib/rudy/mixins/hash.rb
rudy-0.8.5 lib/rudy/mixins/hash.rb
rudy-0.8.3 lib/rudy/mixins/hash.rb
rudy-0.8.4 lib/rudy/mixins/hash.rb
tryouts-0.5.0 lib/tryouts/mixins/hash.rb
tryouts-0.4.1 lib/tryouts/mixins/hash.rb
tryouts-0.4.0 lib/tryouts/mixins/hash.rb
tryouts-0.5.1 lib/tryouts/mixins/hash.rb