# File lib/amrita/node.rb, line 585def 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)
endendend
Public Instance methods
apply_to_children(&block) {|n| ...}
# File lib/amrita/node_expand.rb, line 342def apply_to_children(&block)
ret =@array.collect do |n|
yield(n)
end
Node::to_node(ret)
end
==(x)
# File lib/amrita/node.rb, line 597def ==(x)
returnfalseunless x.kind_of?(NodeArray)
case x
when NodeArray, Array
returnfalseunless x.size() == @array.size()
@array.each_with_index do |n, i|
returnfalseunless n == x[i]
endtrueelsefalseendend
size()
# File lib/amrita/node.rb, line 611def size()
@array.size()
end
[](index)
# File lib/amrita/node.rb, line 615def [](index)
@array[index]
end
no_child?()
# File lib/amrita/node.rb, line 619def no_child?
@array.empty?
end
clone()
# File lib/amrita/node.rb, line 623def clone
NodeArray.new(self)
end
children()
# File lib/amrita/node.rb, line 627def children
@array
end
+(node)
# File lib/amrita/node.rb, line 631def +(node)
ret = clone
ret << node
ret
end
<<(node)
# File lib/amrita/node.rb, line 637def <<(node)
raise "can't be a parent of me!"if node == self
@array << to_node(node)
selfend