Class Hash

  1. lib/rudy/mixins.rb
Parent: Object

Methods

public instance

  1. deepest_point

Public instance methods

deepest_point (h=self, steps=0)

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
[show source]
    # File lib/rudy/mixins.rb, line 17
17:   def deepest_point(h=self, steps=0)
18:     if h.is_a?(Hash)
19:       steps += 1
20:       h.each_pair do |n,possible_h|
21:         ret = deepest_point(possible_h, steps)
22:         steps = ret if steps < ret
23:       end
24:     else
25:       return 0
26:     end
27:     steps
28:   end