Class: RBI::RBS::MethodTypeTranslator

Inherits:
Object
  • Object
show all
Defined in:
lib/rbi/rbs/method_type_translator.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method) ⇒ MethodTypeTranslator

: (Method) -> void



22
23
24
25
# File 'lib/rbi/rbs/method_type_translator.rb', line 22

def initialize(method)
  @method = method
  @result = Sig.new #: Sig
end

Instance Attribute Details

#resultObject (readonly)

: Sig



19
20
21
# File 'lib/rbi/rbs/method_type_translator.rb', line 19

def result
  @result
end

Class Method Details

.translate(method, type) ⇒ Object

: (Method, ::RBS::MethodType) -> Sig



11
12
13
14
15
# File 'lib/rbi/rbs/method_type_translator.rb', line 11

def translate(method, type)
  translator = new(method)
  translator.visit(type)
  translator.result
end

Instance Method Details

#visit(type) ⇒ Object

: (::RBS::MethodType) -> void



28
29
30
31
32
33
34
35
36
37
# File 'lib/rbi/rbs/method_type_translator.rb', line 28

def visit(type)
  type.type_params.each do |param|
    result.type_params << param.name
  end

  visit_function_type(type.type)

  block = type.block
  visit_block_type(block) if block
end