Class: Steep::AST::Builtin::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/ast/builtin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(module_name, arity: 0) ⇒ Type

Returns a new instance of Type.



8
9
10
11
# File 'lib/steep/ast/builtin.rb', line 8

def initialize(module_name, arity: 0)
  @module_name = RBS::TypeName.parse(module_name)
  @arity = arity
end

Instance Attribute Details

#arityObject (readonly)

Returns the value of attribute arity.



6
7
8
# File 'lib/steep/ast/builtin.rb', line 6

def arity
  @arity
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



5
6
7
# File 'lib/steep/ast/builtin.rb', line 5

def module_name
  @module_name
end

Instance Method Details

#instance_type(*args, fill_untyped: false) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/steep/ast/builtin.rb', line 13

def instance_type(*args, fill_untyped: false)
  if fill_untyped
    (arity - args.size).times do
      args << Builtin.any_type
    end
  end
  arity == args.size or raise "Malformed instance type: name=#{module_name}, args=#{args}"

  Types::Name::Instance.new(name: module_name, args: args)
end

#instance_type?(type, args: nil) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/steep/ast/builtin.rb', line 28

def instance_type?(type, args: nil)
  if type.is_a?(Types::Name::Instance)
    if args
      arity == args.size or raise "Malformed instance type: name=#{module_name}, args=#{args}"
      if type.name == module_name && type.args == args
        type
      end
    else
      if type.name == module_name && type.args.size == arity
        type
      end
    end
  end
end

#module_typeObject



24
25
26
# File 'lib/steep/ast/builtin.rb', line 24

def module_type
  Types::Name::Singleton.new(name: module_name)
end

#module_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
# File 'lib/steep/ast/builtin.rb', line 43

def module_type?(type)
  if type.is_a?(Types::Name::Singleton)
    if type.name == module_name
      type
    end
  end
end