class Trie
  attr_reader :value, :children
  attr_accessor :number_exists
  def initialize(value=nil, number_exists=false)
    @value = value
    @children = []
    @number_exists = number_exists # BOOL
  end

  def <<(value)
    sub_trie = Trie.new(value)
    children << sub_trie
    return sub_trie
  end
  #--------------------------------------------------------------------------------------

  def child_value?(value, node)

    if(node.children.empty?)
      return 'empty'                     # Return: 'empty', children[i], 
'D.N.E.'
    else
      i=0; while(i<node.children.size)
        if(node.children[i].value==value)
          return node.children       # Something wrong here ????
        else if(i==node.children.size-1)
          return 'D.N.E.'
        end
      end
      i+=1
      end
    end

  end


  def add_digits(digitArray)

    node = self
    while(digitArray[0])
    scan = child_value?(digitArray[0], node)       # Scan the trie for 
the digit

        # Empty case
        if(scan=='empty')
          node = node<<(digitArray[0])
          if(digitArray.size==1)
            node.number_exists = true
          end
          digitArray.delete(digitArray[0])

        end

    end
  #end function
end


  #--------------------------------------------------------------------------------------
  def add_number(number)
    if(number.is_a?(Fixnum))
      digitArray = []
      number.to_s.each_byte { |byte| digitArray.push(byte.chr.to_i) }
      add_digits(digitArray)
    else
      puts "\'#{number}\' not a valid *Fixnum*"
    end
  end

# End of class Trie
end


t = Trie.new

t.add_number(434)

#984343525
# looking for a (4), (3 and 5)
# 9843--52-
puts "\n"

# Looking for size = 1
puts t.children[0].children[0].children.size


Actually, you can just look at this portion of code
-- 
Posted via http://www.ruby-forum.com/.