Class: T::Types::TEnum

Inherits:
Base
  • Object
show all
Defined in:
lib/types/types/t_enum.rb

Overview

Validates that an object is equal to another T::Enum singleton value.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#valObject (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

#nameObject

overrides Base



14
15
16
17
18
19
20
21
# File 'lib/types/types/t_enum.rb', line 14

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

Returns:



24
25
26
# File 'lib/types/types/t_enum.rb', line 24

def valid?(obj)
  @val == obj
end