Class AbstractNode
In: lib/abstract_node.rb
Parent: Object

$LastChangedBy: pouillar $ $Id: /w/fey/ruby_ex/trunk/lib/abstract_node.rb 21865 2006-02-18T17:13:28.680350Z pouillar $

Methods

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

Included Modules

Abstract

Attributes

data  [R] 
sub_nodes  [R] 

Public Class methods

[Source]

# File lib/abstract_node.rb, line 12
  def initialize(data=nil, *sub_nodes)
    @data = data
    self.each_node { |sub_node| check_sub_node_type(sub_node) }
  end

Public Instance methods

[Source]

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

[Source]

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

[Source]

# File lib/abstract_node.rb, line 46
  def delete(index)
    @sub_nodes.delete(index)
  end
each(&block)

Alias for each_node

[Source]

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

[Source]

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

[Source]

# File lib/abstract_node.rb, line 32
  def each_pair(&block)
    @sub_nodes.each_pair { |index, sub_node| block[index, sub_node] }
  end

[Source]

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

Alias for nb_sub_nodes

[Source]

# File lib/abstract_node.rb, line 28
  def merge!(sub_nodes)
    sub_nodes.each { |index, sub_node| self[index] = sub_node }
  end

[Source]

# File lib/abstract_node.rb, line 50
  def nb_sub_nodes
    @sub_nodes.size
  end

[Source]

# File lib/abstract_node.rb, line 61
  def pre_depth_first(index=nil, &block)
    block[index, self]
    @sub_nodes.each_pair do |index, sub_node|
      sub_node.pre_depth_first(index, &block)
    end
    nil
  end
size()

Alias for nb_sub_nodes

Protected Instance methods

FIXME: implement me def breadth_first(&block) end

[Source]

# File lib/abstract_node.rb, line 74
  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]