Class: Toys::Acceptor::Enum
Overview
Defined in the toys-core gem
An acceptor that recognizes a fixed set of values.
You provide a list of valid values. The input argument string will be matched against the string forms of these valid values. If it matches, the converter will return the actual value from the valid list.
For example, you could pass [:one, :two, 3]
as the set of values. If
an argument of "two"
is passed in, the converter will yield a final
value of the symbol :two
. If an argument of "3" is passed in, the
converter will yield the integer 3
. If an argument of "three" is
passed in, the match will fail.
Instance Attribute Summary collapse
-
#values ⇒ Array<Object>
readonly
The array of enum values.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(values, type_desc: nil, well_known_spec: nil) ⇒ Enum
constructor
Create an acceptor.
Methods inherited from Base
#convert, #match, #suggestions, #to_s
Constructor Details
#initialize(values, type_desc: nil, well_known_spec: nil) ⇒ Enum
Create an acceptor.
245 246 247 |
# File 'core-docs/toys/acceptor.rb', line 245 def initialize(values, type_desc: nil, well_known_spec: nil) # Source available in the toys-core gem end |
Instance Attribute Details
#values ⇒ Array<Object> (readonly)
The array of enum values.
253 254 255 |
# File 'core-docs/toys/acceptor.rb', line 253 def values @values end |