Class Node
In: lib/node.rb
Parent: Object

$LastChangedBy: polrop $ $Id: node.rb 171 2005-03-29 09:12:47Z polrop $

Methods

<<   []   []=   check_sub_node_type   delete   each   each_index   each_node   each_pair   leaf?   length   nb_sub_nodes   new   pre_depth_first   size  

Attributes

data  [R] 
sub_nodes  [R] 

Public Class methods

[Source]

# File lib/node.rb, line 11
  def initialize(data=nil, *sub_nodes)
    @data = data
    sub_nodes.each { |sub_node| check_sub_node_type(sub_node) }
    @sub_nodes = sub_nodes
  end

Public Instance methods

[Source]

# File lib/node.rb, line 28
  def <<(sub_node)
    check_sub_node_type(sub_node)
    @sub_nodes << sub_node
  end

[Source]

# File lib/node.rb, line 19
  def [](sub_node_index)
    @sub_nodes[sub_node_index]
  end

[Source]

# File lib/node.rb, line 23
  def []=(sub_node_index, sub_node)
    check_sub_node_type(sub_node)
    @sub_nodes[sub_node_index] = sub_node
  end

[Source]

# File lib/node.rb, line 47
  def delete(sub_node)
    @sub_nodes.delete(sub_node)
  end
each(&block)

Alias for each_node

[Source]

# File lib/node.rb, line 43
  def each_index(&block)
    @sub_nodes.each_with_index { |sub_node, index| block[index] }
  end

[Source]

# File lib/node.rb, line 37
  def each_node(&block)
    @sub_nodes.each_with_index { |sub_node, index| block[sub_node] }
  end

[Source]

# File lib/node.rb, line 33
  def each_pair(&block)
    @sub_nodes.each_with_index { |sub_node, i| block[i, sub_node] }
  end

[Source]

# File lib/node.rb, line 58
  def leaf?
    @sub_nodes.empty?
  end
length()

Alias for nb_sub_nodes

[Source]

# File lib/node.rb, line 51
  def nb_sub_nodes
    @sub_nodes.size
  end

[Source]

# File lib/node.rb, line 62
  def pre_depth_first(&block)
    block[self]
    @sub_nodes.each { |sub_node| sub_node.pre_depth_first(&block) }
    nil
  end
size()

Alias for nb_sub_nodes

Protected Instance methods

FIXME: implement me def breadth_first(&block) end

[Source]

# File lib/node.rb, line 73
  def check_sub_node_type(sub_node)
    unless sub_node.is_a?(self.class)
      raise(TypeError, "`#{sub_node}' - must be a #{self.class}")
    end
  end

[Validate]