Class: Decode::RBS::Module

Inherits:
Wrapper
  • Object
show all
Defined in:
lib/decode/rbs/module.rb

Overview

Represents a Ruby module definition wrapper for RBS generation.

Instance Method Summary collapse

Methods inherited from Wrapper

#comment, #tags

Constructor Details

#initialize(definition) ⇒ Module

Initialize a new module wrapper.



18
19
20
# File 'lib/decode/rbs/module.rb', line 18

def initialize(definition)
  super
end

Instance Method Details

#to_rbs_ast(method_definitions = [], constant_definitions = [], attribute_definitions = [], index = nil) ⇒ Object

Convert the module definition to RBS AST



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/decode/rbs/module.rb', line 28

def to_rbs_ast(method_definitions = [], constant_definitions = [], attribute_definitions = [], index = nil)
  name = simple_name_to_rbs(@definition.name)
  comment = self.comment
  
  # Build method definitions
  methods = method_definitions.map{|method_def| Method.new(method_def).to_rbs_ast(index)}.compact
  
  # Build constant definitions:
  constants = constant_definitions.map{|const_def| build_constant_rbs(const_def)}.compact
  
  # Build attribute definitions and infer instance variable types:
  attributes, instance_variables = build_attributes_rbs(attribute_definitions)
  
  ::RBS::AST::Declarations::Module.new(
    name: name,
    type_params: [],
    self_types: [],
    members: constants + attributes + instance_variables + methods,
    annotations: [],
    location: nil,
    comment: comment
  )
end