Class: Literal::Tuple::Generic

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*types) ⇒ Generic

Returns a new instance of Generic.



7
8
9
# File 'lib/literal/tuple.rb', line 7

def initialize(*types)
	@types = types
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



11
12
13
# File 'lib/literal/tuple.rb', line 11

def types
  @types
end

Instance Method Details

#===(other) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/literal/tuple.rb', line 13

def ===(other)
	return false unless Literal::Tuple === other
	types = @types
	other_types = other.__types__

	return false unless types.size == other_types.size

	i, len = 0, types.size
	while i < len
		return false unless Literal.subtype?(other_types[i], types[i])
		i += 1
	end

	true
end

#>=(other) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/literal/tuple.rb', line 29

def >=(other)
	case other
	when Literal::Tuple::Generic
		types = @types
		other_types = other.types

		return false unless types.size == other_types.size

		i, len = 0, types.size
		while i < len
			return false unless Literal.subtype?(other_types[i], types[i])
			i += 1
		end

		true
	else
		false
	end
end

#new(*values) ⇒ Object



49
50
51
# File 'lib/literal/tuple.rb', line 49

def new(*values)
	Literal::Tuple.new(values, @types)
end