Class: T::Types::TEnum
Overview
Validates that an object is equal to another T::Enum singleton value.
Instance Attribute Summary collapse
-
#val ⇒ Object
readonly
Returns the value of attribute val.
Instance Method Summary collapse
- #build_type ⇒ Object
-
#initialize(val) ⇒ TEnum
constructor
A new instance of TEnum.
-
#name ⇒ Object
overrides Base.
-
#valid?(obj) ⇒ Boolean
overrides Base.
Methods inherited from Base
#==, #describe_obj, #error_message_for_obj, #error_message_for_obj_recursive, #hash, method_added, #recursively_valid?, #subtype_of?, #to_s, #validate!
Constructor Details
#initialize(val) ⇒ TEnum
Returns a new instance of TEnum.
9 10 11 |
# File 'lib/types/types/t_enum.rb', line 9 def initialize(val) @val = val end |
Instance Attribute Details
#val ⇒ Object (readonly)
Returns the value of attribute val.
7 8 9 |
# File 'lib/types/types/t_enum.rb', line 7 def val @val end |
Instance Method Details
#build_type ⇒ Object
13 14 15 |
# File 'lib/types/types/t_enum.rb', line 13 def build_type nil end |
#name ⇒ Object
overrides Base
18 19 20 21 22 23 24 25 |
# File 'lib/types/types/t_enum.rb', line 18 def name # Strips the #<...> off, just leaving the ... # Reasoning: the user will have written something like # T.any(MyEnum::A, MyEnum::B) # in the type, so we should print what they wrote in errors, not: # T.any(#<MyEnum::A>, #<MyEnum::B>) @val.inspect[2..-2] end |
#valid?(obj) ⇒ Boolean
overrides Base
28 29 30 |
# File 'lib/types/types/t_enum.rb', line 28 def valid?(obj) @val == obj end |