Class: Ruby::Node::Composite::Array

Inherits:
Array show all
Includes:
Ruby::Node::Composite
Defined in:
lib/ruby/node/composite.rb

Instance Attribute Summary

Attributes included from Ruby::Node::Composite

#parent

Instance Method Summary collapse

Methods included from Ruby::Node::Composite

included, #root, #root?

Methods inherited from Array

#flush

Constructor Details

#initialize(objects = []) ⇒ Array

Returns a new instance of Array.



7
8
9
# File 'lib/ruby/node/composite.rb', line 7

def initialize(objects = [])
  objects.each { |object| self << object }
end

Instance Method Details

#+(other) ⇒ Object



34
35
36
# File 'lib/ruby/node/composite.rb', line 34

def +(other)
  self.dup.tap { |dup| other.each { |object| dup << object } }
end

#<<(object) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/ruby/node/composite.rb', line 15

def <<(object)
  if object.respond_to?(:parent=)
    object.parent = self.parent 
  elsif object.respond_to?(:each)
    object.each { |o| o.try(:parent=, parent) }
  end
  super
end

#[]=(ix, object) ⇒ Object



24
25
26
27
# File 'lib/ruby/node/composite.rb', line 24

def []=(ix, object)
  object.parent = parent
  super
end

#detectObject



11
12
13
# File 'lib/ruby/node/composite.rb', line 11

def detect
  each { |element| return element if yield(element) }
end

#parent=(parent) ⇒ Object



29
30
31
32
# File 'lib/ruby/node/composite.rb', line 29

def parent=(parent)
  each { |object| object.try(:parent=, parent) }
  @parent = parent
end