Class: Arbre::ElementCollection
- Inherits:
-
Object
- Object
- Arbre::ElementCollection
- Includes:
- Enumerable
- Defined in:
- lib/arbre/element_collection.rb
Direct Known Subclasses
Instance Method Summary collapse
- #&(other) ⇒ Object
-
#+(other) ⇒ Object
Set operations.
- #-(other) ⇒ Object
- #<<(element) ⇒ Object
- #==(other) ⇒ Object
- #[](*args) ⇒ Object
- #add(element) ⇒ Object
- #concat(elements) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(elements = []) ⇒ ElementCollection
constructor
Initialization.
- #remove(element) ⇒ Object
- #to_a ⇒ Object
- #to_ary ⇒ Object
-
#to_s ⇒ Object
String conversion.
Constructor Details
#initialize(elements = []) ⇒ ElementCollection
Initialization
8 9 10 |
# File 'lib/arbre/element_collection.rb', line 8 def initialize(elements = []) @elements = elements.to_a end |
Instance Method Details
#&(other) ⇒ Object
69 70 71 |
# File 'lib/arbre/element_collection.rb', line 69 def &(other) self.class.new(@elements & other) end |
#+(other) ⇒ Object
Set operations
61 62 63 |
# File 'lib/arbre/element_collection.rb', line 61 def +(other) self.class.new((@elements + other).uniq) end |
#-(other) ⇒ Object
65 66 67 |
# File 'lib/arbre/element_collection.rb', line 65 def -(other) self.class.new(@elements - other) end |
#<<(element) ⇒ Object
29 30 31 |
# File 'lib/arbre/element_collection.rb', line 29 def <<(element) add element end |
#==(other) ⇒ Object
50 51 52 |
# File 'lib/arbre/element_collection.rb', line 50 def ==(other) to_a == other.to_a end |
#[](*args) ⇒ Object
19 20 21 22 23 |
# File 'lib/arbre/element_collection.rb', line 19 def [](*args) result = @elements[*args] result = self.class.new(result) if result.is_a?(Enumerable) result end |
#add(element) ⇒ Object
25 26 27 28 |
# File 'lib/arbre/element_collection.rb', line 25 def add(element) @elements << element unless include?(element) self end |
#concat(elements) ⇒ Object
33 34 35 36 37 |
# File 'lib/arbre/element_collection.rb', line 33 def concat(elements) elements.each do |element| self << element end end |
#eql?(other) ⇒ Boolean
54 55 56 |
# File 'lib/arbre/element_collection.rb', line 54 def eql?(other) other.is_a?(ElementCollection) && self == other end |
#remove(element) ⇒ Object
39 40 41 |
# File 'lib/arbre/element_collection.rb', line 39 def remove(element) @elements.delete element end |
#to_a ⇒ Object
46 47 48 |
# File 'lib/arbre/element_collection.rb', line 46 def to_a @elements.dup end |
#to_ary ⇒ Object
43 44 45 |
# File 'lib/arbre/element_collection.rb', line 43 def to_ary @elements end |
#to_s ⇒ Object
String conversion
76 77 78 |
# File 'lib/arbre/element_collection.rb', line 76 def to_s html_safe_join(map(&:to_s), "\n") end |