Module: Literal::Constructors

Included in:
Literal
Defined in:
lib/literal/constructors.rb

Instance Method Summary collapse

Instance Method Details

#Array(type) ⇒ Literal::Array

Returns:



5
6
7
# File 'lib/literal/constructors.rb', line 5

def Array(type)
	Literal::ArrayType.new(type)
end

#Decorator(object_type) ⇒ Literal::Decorator

Returns:



24
25
26
27
28
# File 'lib/literal/constructors.rb', line 24

def Decorator(object_type)
	Class.new(Literal::Decorator) do
		attribute :__object__, object_type, positional: true, reader: :public, writer: :private
	end
end

#LRU(key_type, value_type) ⇒ Literal::LRU

Returns:



10
11
12
# File 'lib/literal/constructors.rb', line 10

def LRU(key_type, value_type)
	Literal::LRUType.new(key_type, value_type)
end

#Union(*types) ⇒ Literal::Union

Returns:



31
32
33
# File 'lib/literal/constructors.rb', line 31

def Union(*types)
	Literal::Union.new(*types)
end

#Value(type) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/literal/constructors.rb', line 35

def Value(type, &)
	value_class = Literal::ValueClasses[type]

	unless value_class
		raise Literal::ArgumentError, "Invalid value type."
	end

	Class.new(value_class, &)
end

#Variant(*types) ⇒ Literal::Variant

Returns:



15
16
17
18
19
20
21
# File 'lib/literal/constructors.rb', line 15

def Variant(*types)
	if block_given?
		Literal::Variant.new(yield, *types)
	else
		Literal::VariantType.new(*types)
	end
end