Class: Amrita::NodeArray

Class Amrita::NodeArray |
In: | lib/amrita/node_expand.rb lib/amrita/node.rb lib/amrita/format.rb lib/amrita/compiler.rb
Parent: | Object

represents an Array of Node. It is a Node also.

Methods

+ << == [] apply_to_children children clone compile format new no_child? pre_format1 size to_ruby

Attributes

:array | [R] |

Included modules

Node

Public Class methods

new(*elements)

    # File lib/amrita/node.rb, line 585
        def initialize(*elements)
          if elements.size() == 1 and elements[0].kind_of?(NodeArray)
            a = elements[0]
            @array = a.array.collect { |n| n.clone }
          else
            @array = elements.collect do |a|
              #raise "can't be a parent of me!" if a.id == self.id # no recusive check because it costs too much
              to_node(a)
            end
          end
        end

Public Instance methods

apply_to_children(&block) {|n| ...}

    # File lib/amrita/node_expand.rb, line 342
        def apply_to_children(&block)
          ret =@array.collect do |n|
            yield(n)
          end
          Node::to_node(ret)
        end

==(x)

    # File lib/amrita/node.rb, line 597
        def ==(x)
          return false unless x.kind_of?(NodeArray)
          case x
          when NodeArray, Array
            return false unless x.size() == @array.size()
            @array.each_with_index do |n, i|
              return false unless n == x[i]
            end
            true
          else
            false
          end
        end

size()

    # File lib/amrita/node.rb, line 611
        def size()
          @array.size()
        end

[](index)

    # File lib/amrita/node.rb, line 615
        def [](index)
          @array[index]
        end

no_child?()

    # File lib/amrita/node.rb, line 619
        def no_child?
          @array.empty?
        end

clone()

    # File lib/amrita/node.rb, line 623
        def clone
          NodeArray.new(self)
        end

children()

    # File lib/amrita/node.rb, line 627
        def children
          @array
        end

+(node)

    # File lib/amrita/node.rb, line 631
        def +(node)
          ret = clone
          ret << node
          ret
        end

<<(node)

    # File lib/amrita/node.rb, line 637
        def <<(node)
          raise "can't be a parent of me!" if node == self
          @array << to_node(node)
          self
        end

to_ruby()

    # File lib/amrita/node.rb, line 643
        def to_ruby
          "[ " + @array.collect {|e| e.to_ruby}.join(", ") + " ]"
        end

format(f)

    # File lib/amrita/format.rb, line 577
        def format(f)
          @array.each { |n| n.format(f) }
        end

pre_format1(prf)

    # File lib/amrita/format.rb, line 581
        def pre_format1(prf)
          @array.each do |n|
            n.pre_format1(prf)
          end
        end

compile(compiler)

    # File lib/amrita/compiler.rb, line 105
        def compile(compiler)
          children.each { |node| node.compile(compiler) }
        end