Class: Ruby::Node::Composite::Array
- Includes:
- Ruby::Node::Composite
- Defined in:
- lib/ruby/node/composite.rb
Instance Attribute Summary
Attributes included from Ruby::Node::Composite
Instance Method Summary collapse
- #+(other) ⇒ Object
- #<<(object) ⇒ Object
- #[]=(ix, object) ⇒ Object
- #detect ⇒ Object
-
#initialize(objects = []) ⇒ Array
constructor
A new instance of Array.
- #parent=(parent) ⇒ Object
Methods included from Ruby::Node::Composite
Methods inherited from Array
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 |
#detect ⇒ Object
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 |