Class: Enumerize::Set
Instance Attribute Summary collapse
Instance Method Summary
collapse
#method_missing, #respond_to_missing?
Constructor Details
#initialize(obj, attr, values) ⇒ Set
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/enumerize/set.rb', line 8
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
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Enumerize::Predicatable
Instance Attribute Details
#values ⇒ Object
Returns the value of attribute values.
6
7
8
|
# File 'lib/enumerize/set.rb', line 6
def values
@values
end
|
Instance Method Details
#<<(value) ⇒ Object
Also known as:
push
21
22
23
24
|
# File 'lib/enumerize/set.rb', line 21
def <<(value)
@values << value
mutate!
end
|
#==(other) ⇒ Object
Also known as:
eql?
36
37
38
|
# File 'lib/enumerize/set.rb', line 36
def ==(other)
other.size == size && other.all? { |v| @values.include?(@attr.find_value(v)) }
end
|
#delete(value) ⇒ Object
46
47
48
49
|
# File 'lib/enumerize/set.rb', line 46
def delete(value)
@values.delete(@attr.find_value(value))
mutate!
end
|
#include?(value) ⇒ Boolean
42
43
44
|
# File 'lib/enumerize/set.rb', line 42
def include?(value)
@values.include?(@attr.find_value(value))
end
|
#inspect ⇒ Object
51
52
53
|
# File 'lib/enumerize/set.rb', line 51
def inspect
"#<Enumerize::Set {#{join(', ')}}>"
end
|
#to_ary ⇒ Object
30
31
32
|
# File 'lib/enumerize/set.rb', line 30
def to_ary
@values.to_a
end
|