Class: Yoda::Typing::Types::Method

Inherits:
Base
  • Object
show all
Defined in:
lib/yoda/typing/types/method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#reference?

Constructor Details

#initialize(callee, method_name, with_receiver: false) ⇒ Method



14
15
16
17
# File 'lib/yoda/typing/types/method.rb', line 14

def initialize(callee, method_name, with_receiver: false)
  @callee = callee
  @method_name = method_name
end

Instance Attribute Details

#calleeBase (readonly)



6
7
8
# File 'lib/yoda/typing/types/method.rb', line 6

def callee
  @callee
end

#method_nameString (readonly)



9
10
11
# File 'lib/yoda/typing/types/method.rb', line 9

def method_name
  @method_name
end

Instance Method Details

#to_expression(resolver) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/yoda/typing/types/method.rb', line 19

def to_expression(resolver)
  callee_type = to_expression(callee)
  values = callee_type.instanciate(resolver.registry)
  Model::TypeExpressions::UnionType.new(
    values.map do |value|
      value.methods(visibility: visibility).select { |func| func.name == method_name }
    end.flatten
  )
end

#to_type_stringObject



33
34
35
# File 'lib/yoda/typing/types/method.rb', line 33

def to_type_string
  "#{callee.to_type_string}##{method_name}"
end

#visilibityObject



29
30
31
# File 'lib/yoda/typing/types/method.rb', line 29

def visilibity
  @self_call ? [:private, :public, :protected] : [:public]
end