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

Returns a new instance of Method.

Parameters:

  • callee (Base)
  • method_name (String)
  • with_receiver (true, false) (defaults to: false)


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

#callee ⇒ Base (readonly)

Returns:



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

def callee
  @callee
end

#method_name ⇒ String (readonly)

Returns:

  • (String)


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_string ⇒ Object



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

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

#visilibity ⇒ Object



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

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