Class: Literal::Types::TupleType Private

Inherits:
Object
  • Object
show all
Includes:
Literal::Type
Defined in:
lib/literal/types/tuple_type.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*types) ⇒ TupleType

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TupleType.



7
8
9
10
11
12
# File 'lib/literal/types/tuple_type.rb', line 7

def initialize(*types)
	raise Literal::ArgumentError.new("_Tuple type must have at least one type.") if types.size < 1

	@types = types
	freeze
end

Instance Attribute Details

#typesObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
# File 'lib/literal/types/tuple_type.rb', line 14

def types
  @types
end

Instance Method Details

#===(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/literal/types/tuple_type.rb', line 20

def ===(value)
	return false unless Array === value
	types = @types
	return false unless value.size == types.size

	i, len = 0, types.size
	while i < len
		return false unless types[i] === value[i]
		i += 1
	end

	true
end

#>=(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



50
51
52
53
54
55
56
57
# File 'lib/literal/types/tuple_type.rb', line 50

def >=(other)
	case other
	when Literal::Types::TupleType
		@types == other.types
	else
		false
	end
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
# File 'lib/literal/types/tuple_type.rb', line 16

def inspect
	"_Tuple(#{@types.map(&:inspect).join(', ')})"
end

#record_literal_type_errors(context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/literal/types/tuple_type.rb', line 34

def record_literal_type_errors(context)
	return unless Array === context.actual

	len = [@types.size, context.actual.size].max
	i = 0
	while i < len
		actual = context.actual[i]
		if !(expected = @types[i])
			context.add_child(label: "[#{i}]", expected: Literal::Types::NeverType::Instance, actual:)
		elsif !(expected === actual)
			context.add_child(label: "[#{i}]", expected:, actual:)
		end
		i += 1
	end
end