class Enumerize::Set

Attributes

values[R]

Public Class Methods

new(obj, attr, values) click to toggle source
# File lib/enumerize/set.rb, line 7
def initialize(obj, attr, values)
  @obj    = obj
  @attr   = attr
  @values = ::Set.new

  if values.respond_to?(:each)
    values.each do |input|
      value = @attr.find_value(input)
      @values << value if value
    end
  end
end

Public Instance Methods

<<(value) click to toggle source
# File lib/enumerize/set.rb, line 20
def <<(value)
  @values << value
  mutate!
end
Also aliased as: push
==(other) click to toggle source
# File lib/enumerize/set.rb, line 35
def ==(other)
  other.size == size && other.all? { |v| @values.include?(@attr.find_value(v)) }
end
Also aliased as: eql?
delete(value) click to toggle source
# File lib/enumerize/set.rb, line 45
def delete(value)
  @values.delete(@attr.find_value(value))
  mutate!
end
eql?(other)
Alias for: ==
include?(value) click to toggle source
# File lib/enumerize/set.rb, line 41
def include?(value)
  @values.include?(@attr.find_value(value))
end
inspect() click to toggle source
# File lib/enumerize/set.rb, line 50
def inspect
  "#<Enumerize::Set {#{join(', ')}}>"
end
push(value)
Alias for: <<
to_ary() click to toggle source
# File lib/enumerize/set.rb, line 29
def to_ary
  @values.to_a
end

Private Instance Methods

mutate!() click to toggle source
# File lib/enumerize/set.rb, line 56
def mutate!
  @values = @obj.public_send("#{@attr.name}=", @values).values
end