Class: TypeProf::Core::Type
- Inherits:
-
Object
- Object
- TypeProf::Core::Type
show all
- Defined in:
- lib/typeprof/core/type.rb
Defined Under Namespace
Classes: Array, Bot, Hash, Instance, Proc, Record, Singleton, Symbol, Var
Class Method Summary
collapse
Class Method Details
.default_param_map(genv, ty) ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/typeprof/core/type.rb', line 32
def self.default_param_map(genv, ty)
ty = ty.base_type(genv)
instance_ty = ty.is_a?(Type::Instance) ? ty : Type::Instance.new(genv, ty.mod, [])
singleton_ty = ty.is_a?(Type::Instance) ? Type::Singleton.new(genv, ty.mod) : ty
{
"*self": Source.new(ty),
"*instance": Source.new(instance_ty),
"*class": Source.new(singleton_ty),
}
end
|
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/typeprof/core/type.rb', line 18
def self.(s)
if s.start_with?("Hash[") && s.end_with?("]")
type = RBS::Parser.parse_type(s)
if type.is_a?(RBS::Types::Union)
type.types.map {|t| t.args[1].to_s }.join(" | ")
else
type.args[1].to_s
end
else
s
end
end
|
.new(genv, *args) ⇒ Object
This new method does memoize creation of types : (GlobalEnv, *untyped) -> instance
5
6
7
|
# File 'lib/typeprof/core/type.rb', line 5
def self.new(genv, *args)
genv.type_table[[self] + args] ||= super(genv, *args)
end
|
.strip_array(s) ⇒ Object
14
15
16
|
# File 'lib/typeprof/core/type.rb', line 14
def self.strip_array(s)
s.start_with?("Array[") && s.end_with?("]") ? s[6..-2] || raise : s
end
|
.strip_parens(s) ⇒ Object
9
10
11
12
|
# File 'lib/typeprof/core/type.rb', line 9
def self.strip_parens(s)
s.start_with?("(") && s.end_with?(")") ? s[1..-2] || raise : s
end
|