From: salamond Date: 2010-10-21T19:38:16+09:00 Subject: Re: about handling args in block Thanks Jeremy, wax, and robert. I wanner do this because this tree may not be a binary tree. What if a node could link to a dozen nodes. we have to something like this. nodes.each do |node| node = nil end On Thu, Oct 21, 2010 at 4:00 PM, Robert Klemme wrote: > On Thu, Oct 21, 2010 at 6:10 AM, w_a_x_man wrote: >> On Oct 20, 11:41 am, Robert Klemme wrote: >> >>> Node = Struct.new :value, :left, :right do >>> >>>    # We usually do not use prefix "is" which >>>    # you might be used to in Java. >>>    def leaf? >>>      @left.nil? && @right.nil? >>>    end >> >> Will that work? Or would it have to be >> >>    self.left.nil? && self.right.nil? > > No, my code won't work.  But this is sufficient: > > left.nil? && right.nil? > > It also needs to be > >  def visit(val = nil, &b) >   val = left.visit(val, &b) if left >   val = b[self, val] >   val = right.visit(val, &b) if right >   val >  end > > Thanks for catching this! > > Kind regards > > robert > > > -- > remember.guy do |as, often| as.you_can - without end > http://blog.rubybestpractices.com/ > >