Class: Highway::Steps::Types::Enum
- Defined in:
- lib/highway/steps/types/enum.rb
Overview
This class represents an enum parameter type. It can be used in parameters which have a finite set of valid values.
Instance Method Summary collapse
-
#initialize(*values) ⇒ Enum
constructor
Initialize an instance.
-
#typecheck(value) ⇒ String?
Typecheck and coerce a value if possible.
Methods inherited from String
Methods inherited from Any
#typecheck_and_validate, #validate
Constructor Details
#initialize(*values) ⇒ Enum
Initialize an instance.
22 23 24 25 |
# File 'lib/highway/steps/types/enum.rb', line 22 def initialize(*values) super(validate: nil) @values = values end |
Instance Method Details
#typecheck(value) ⇒ String?
Typecheck and coerce a value if possible.
This method returns a typechecked and coerced value or ‘nil` if value has invalid type and can’t be coerced.
35 36 37 38 |
# File 'lib/highway/steps/types/enum.rb', line 35 def typecheck(value) typechecked = super(value) typechecked if !typechecked.nil? && @values.include?(typechecked) end |