Class: Repeatable::Expression::Set
- Defined in:
- lib/repeatable/expression/set.rb
Direct Known Subclasses
Instance Method Summary collapse
- #<<(element) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(*elements) ⇒ Set
constructor
A new instance of Set.
- #to_h ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(*elements) ⇒ Set
Returns a new instance of Set.
4 5 6 |
# File 'lib/repeatable/expression/set.rb', line 4 def initialize(*elements) @elements = elements.flatten.uniq end |
Instance Method Details
#<<(element) ⇒ Object
8 9 10 11 |
# File 'lib/repeatable/expression/set.rb', line 8 def <<(element) elements << element unless elements.include?(element) self end |
#==(other) ⇒ Object
17 18 19 20 21 |
# File 'lib/repeatable/expression/set.rb', line 17 def ==(other) other.is_a?(self.class) && elements.size == other.elements.size && other.elements.all? { |e| elements.include?(e) } end |
#to_h ⇒ Object
13 14 15 |
# File 'lib/repeatable/expression/set.rb', line 13 def to_h Hash[hash_key, elements.map(&:to_h)] end |