class Hash
def deepest_point(h=self, steps=0)
ahash.deepest_point # => 3
ahash = { :level1 => { :level2 => {} } }
number is the depth of its children + 1. An example:
The top level Hash is counted in the total so the final
A depth-first look to find the deepest point in the Hash.
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
def last
NOTE: This method is defined only when Hash.method_defined?(:last)
Tryouts to @@instances.
It's used in Tryouts to return the most recently added instance of
Ruby 1.9 doesn't have a Hash#last (but Tryouts::OrderedHash does).
def last self[ self.keys.last ] end