Class: Repeatable::Expression::Set
- Defined in:
- lib/repeatable/expression/set.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
Instance Method Summary collapse
- #<<(element) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(elements) ⇒ Set
constructor
A new instance of Set.
Methods inherited from Base
===, #deconstruct_keys, #difference, #include?, #intersection, #to_h, #union
Constructor Details
#initialize(elements) ⇒ Set
Returns a new instance of Set.
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
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
9 10 11 |
# File 'lib/repeatable/expression/set.rb', line 9 def elements @elements end |
Instance Method Details
#<<(element) ⇒ Object
17 18 19 20 |
# File 'lib/repeatable/expression/set.rb', line 17 def <<(element) elements << element unless elements.include?(element) self end |
#==(other) ⇒ Object
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 |