Class: RBI::RBS::MethodTypeTranslator

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

Defined Under Namespace

Classes: Error, Options

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, options: Options.default) ⇒ MethodTypeTranslator

: (Method, ?options: Options) -> void



38
39
40
41
42
43
44
# File 'lib/rbi/rbs/method_type_translator.rb', line 38

def initialize(method, options: Options.default)
  @method = method
  @options = options

  @result = Sig.new #: Sig
  @type_translator = TypeTranslator.new(options: @options) #: TypeTranslator
end

Instance Attribute Details

#resultObject (readonly)

: Sig



35
36
37
# File 'lib/rbi/rbs/method_type_translator.rb', line 35

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



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rbi/rbs/method_type_translator.rb', line 47

def visit(type)
  unless @options.erase_generic_types
    type.type_params.each do |param|
      result.type_params << param.name
    end
  end

  visit_function_type(type.type)

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