lib/repeatable/expression/set.rb in repeatable-0.3.0 vs lib/repeatable/expression/set.rb in repeatable-0.4.0

- old
+ new

@@ -1,23 +1,27 @@ module Repeatable module Expression class Set < Base def initialize(*elements) - @elements = elements.flatten + @elements = elements.flatten.uniq end def <<(element) - elements << element + elements << element unless elements.include?(element) self end def to_h - hash = {} - hash[self.class.name.demodulize.underscore.to_sym] = elements.map(&:to_h) - hash + Hash[hash_key, elements.map(&:to_h)] end - private + def ==(other) + other.is_a?(self.class) && + elements.size == other.elements.size && + other.elements.all? { |e| elements.include?(e) } + end + + protected attr_reader :elements end end end