Class: Repeatable::Expression::Set
Abstract
- Inherits:
-
Base
- Object
- Base
- Repeatable::Expression::Set
show all
- Defined in:
- lib/repeatable/expression/set.rb
Overview
This class is abstract.
It cannot be directly instantiated. Subclasses must implement the ‘abstract` methods below.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
===, #deconstruct_keys, #difference, #include?, #intersection, #to_h, #union
Constructor Details
#initialize(elements) ⇒ void
12
13
14
|
# File 'lib/repeatable/expression/set.rb', line 12
def initialize(elements)
@elements = T.let(elements.flatten.uniq, T::Array[Expression::Base])
end
|
Instance Attribute Details
9
10
11
|
# File 'lib/repeatable/expression/set.rb', line 9
def elements
@elements
end
|
Instance Method Details
17
18
19
20
|
# File 'lib/repeatable/expression/set.rb', line 17
def <<(element)
elements << element unless elements.include?(element)
self
end
|
#==(other) ⇒ Boolean
23
24
25
26
27
|
# File 'lib/repeatable/expression/set.rb', line 23
def ==(other)
other.is_a?(self.class) &&
elements.size == other.elements.size &&
other.elements.all? { |e| elements.include?(e) }
end
|