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.
- #to_h ⇒ Object
Methods inherited from Base
===, #difference, #include?, #intersection, #union
Constructor Details
#initialize(*elements) ⇒ Set
Returns a new instance of Set.
6 7 8 |
# File 'lib/repeatable/expression/set.rb', line 6 def initialize(*elements) @elements = elements.flatten.uniq end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
4 5 6 |
# File 'lib/repeatable/expression/set.rb', line 4 def elements @elements end |
Instance Method Details
#<<(element) ⇒ Object
10 11 12 13 |
# File 'lib/repeatable/expression/set.rb', line 10 def <<(element) elements << element unless elements.include?(element) self end |
#==(other) ⇒ Object
19 20 21 22 23 |
# File 'lib/repeatable/expression/set.rb', line 19 def ==(other) other.is_a?(self.class) && elements.size == other.elements.size && other.elements.all? { |e| elements.include?(e) } end |
#to_h ⇒ Object
15 16 17 |
# File 'lib/repeatable/expression/set.rb', line 15 def to_h Hash[hash_key, elements.map(&:to_h)] end |