Class: T::Types::Enum
- Extended by:
- Sig
- Defined in:
- lib/types/types/enum.rb
Overview
validates that the provided value is within a given set/enum
Instance Attribute Summary collapse
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #describe_obj(obj) ⇒ Object
-
#initialize(values) ⇒ Enum
constructor
A new instance of Enum.
- #name ⇒ Object
- #valid?(obj) ⇒ Boolean
Methods included from Sig
Methods inherited from Base
#==, #error_message_for_obj, #hash, method_added, #subtype_of?, #to_s, #validate!
Constructor Details
#initialize(values) ⇒ Enum
Returns a new instance of Enum.
13 14 15 |
# File 'lib/types/types/enum.rb', line 13 def initialize(values) @values = values end |
Instance Attribute Details
#values ⇒ Object (readonly)
Returns the value of attribute values.
9 10 11 |
# File 'lib/types/types/enum.rb', line 9 def values @values end |
Instance Method Details
#describe_obj(obj) ⇒ Object
38 39 40 |
# File 'lib/types/types/enum.rb', line 38 def describe_obj(obj) obj.inspect end |
#name ⇒ Object
33 34 35 |
# File 'lib/types/types/enum.rb', line 33 def name "T.enum([#{@values.map(&:inspect).join(', ')}])" end |
#valid?(obj) ⇒ Boolean
18 19 20 |
# File 'lib/types/types/enum.rb', line 18 def valid?(obj) @values.member?(obj) end |