From: Christopher Dicely Date: 2011-05-03T13:28:22+09:00 Subject: Re: Help making a method more concise On Mon, May 2, 2011 at 11:17 AM, Mark Hayes wrote: > Hello, > > I'm looking to improve my skills as a Rubyist and would like to know if the > "depth" method could be expressed more precisely.  Any help would be greatly > appreciated, thanks! > > require 'test/unit' > > class Node >  attr_accessor :value, :lchild, :rchild > >  def depth >    [lchild ? lchild.depth : 0, rchild ? rchild.depth : 0].max + 1 >  end > end def depth 1 + [lchild,rchild].map {|ch| [ch}.max end or even: def depth 1 + [lchild,rchild].map(&:to_i).max end alias to_i depth or: add empty (no value) left & right children when you first add a value to a node, and: def empty? @value.nil? end def depth empty? ? 0 : [lchild,rchild].map(&:depth).max end