Class: Steep::AST::Types::Proc

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params:, return_type:, location: nil) ⇒ Proc

Returns a new instance of Proc.



9
10
11
12
13
# File 'lib/steep/ast/types/proc.rb', line 9

def initialize(params:, return_type:, location: nil)
  @location = location
  @params = params
  @return_type = return_type
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

#return_typeObject (readonly)

Returns the value of attribute return_type.



7
8
9
# File 'lib/steep/ast/types/proc.rb', line 7

def return_type
  @return_type
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



15
16
17
18
19
# File 'lib/steep/ast/types/proc.rb', line 15

def ==(other)
  other.is_a?(self.class) &&
    other.params == params &&
    other.return_type == return_type
end

#back_typeObject



73
74
75
76
77
# File 'lib/steep/ast/types/proc.rb', line 73

def back_type
  Name::Instance.new(name: Builtin::Proc.module_name,
                     args: [],
                     location: location)
end

#closed?Boolean

Returns:



48
49
50
# File 'lib/steep/ast/types/proc.rb', line 48

def closed?
  params.closed? && return_type.closed?
end

#free_variablesObject



39
40
41
# File 'lib/steep/ast/types/proc.rb', line 39

def free_variables
  params.free_variables + return_type.free_variables
end

#hashObject



21
22
23
# File 'lib/steep/ast/types/proc.rb', line 21

def hash
  self.class.hash && params.hash && return_type.hash
end

#levelObject



43
44
45
46
# File 'lib/steep/ast/types/proc.rb', line 43

def level
  children = params.each_type.to_a + [return_type]
  [0] + level_of_children(children)
end

#map_type(&block) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/steep/ast/types/proc.rb', line 56

def map_type(&block)
  self.class.new(
    params: params.map_type(&block),
    return_type: yield(return_type),
    location: location
  )
end

#one_arg?Boolean

Returns:



64
65
66
67
68
69
70
71
# File 'lib/steep/ast/types/proc.rb', line 64

def one_arg?
  params.required.size == 1 &&
    params.optional.empty? &&
    !params.rest &&
    params.required_keywords.empty? &&
    params.optional_keywords.empty? &&
    !params.rest_keywords
end

#subst(s) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/steep/ast/types/proc.rb', line 27

def subst(s)
  self.class.new(
    params: params.subst(s),
    return_type: return_type.subst(s),
    location: location
  )
end

#to_sObject



35
36
37
# File 'lib/steep/ast/types/proc.rb', line 35

def to_s
  "^#{params} -> #{return_type}"
end

#with_location(new_location) ⇒ Object



52
53
54
# File 'lib/steep/ast/types/proc.rb', line 52

def with_location(new_location)
  self.class.new(location: new_location, params: params, return_type: return_type)
end