class EnumX::ValueList

A list of multiple enum values.

Attributes

enum[R]

Attributes

to_a[R]
to_ary[R]
values[R]

Public Class Methods

new(enum, values) click to toggle source

Initialization

# File lib/enum_x/value_list.rb, line 9
def initialize(enum, values)
  @enum = enum
  values = [ values ] unless values.is_a?(Enumerable)
  @values = values.map { |value| @enum[value] || value }
end

Public Instance Methods

==(other) click to toggle source
# File lib/enum_x/value_list.rb, line 57
def ==(other)
  case other
  when Array then values == other
  when EnumX::ValueList then values == other.values
  when EnumX::Value then values == [ other ]
  else false
  end
end
[](value) click to toggle source
# File lib/enum_x/value_list.rb, line 49
def [](value)
  values.find { |val| val.to_s == value.to_s }
end
include?(value) click to toggle source
# File lib/enum_x/value_list.rb, line 53
def include?(value)
  values.any? { |val| val.to_s == value.to_s }
end
to_s() click to toggle source

Creates a string representation of the values.

# File lib/enum_x/value_list.rb, line 34
def to_s
  values.map(&:to_s).join(', ')
end