Class: Primalize::Single::Enum

Inherits:
Object
  • Object
show all
Includes:
Type
Defined in:
lib/primalize/single.rb

Constant Summary

Constants included from Type

Type::DEFAULT_COERCION

Instance Method Summary collapse

Constructor Details

#initialize(values, &coercion) ⇒ Enum

Returns a new instance of Enum.



266
267
268
269
# File 'lib/primalize/single.rb', line 266

def initialize values, &coercion
  @values = values
  @coercion = coercion
end

Instance Method Details

#===(value) ⇒ Object



271
272
273
# File 'lib/primalize/single.rb', line 271

def === value
  @values.include? value
end

#coerce(value) ⇒ Object



275
276
277
# File 'lib/primalize/single.rb', line 275

def coerce value
  super value, @values
end

#inspectObject



279
280
281
# File 'lib/primalize/single.rb', line 279

def inspect
  "enum(#{@values.map(&:inspect).join(', ')})"
end