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

#build_typeObject



13
14
15
# File 'lib/types/types/t_enum.rb', line 13

def build_type
  nil
end

#nameObject

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

Returns:



28
29
30
# File 'lib/types/types/t_enum.rb', line 28

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