Class: RBS::Source::Ruby

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer, prism, declarations, diagnostics) ⇒ Ruby

Returns a new instance of Ruby.



58
59
60
61
62
63
# File 'lib/rbs/source.rb', line 58

def initialize(buffer, prism, declarations, diagnostics)
  @buffer = buffer
  @prism_result = prism
  @declarations = declarations
  @diagnostics = diagnostics
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



53
54
55
# File 'lib/rbs/source.rb', line 53

def buffer
  @buffer
end

#declarationsObject (readonly)

Returns the value of attribute declarations.



55
56
57
# File 'lib/rbs/source.rb', line 55

def declarations
  @declarations
end

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



56
57
58
# File 'lib/rbs/source.rb', line 56

def diagnostics
  @diagnostics
end

#prism_resultObject (readonly)

Returns the value of attribute prism_result.



54
55
56
# File 'lib/rbs/source.rb', line 54

def prism_result
  @prism_result
end

Instance Method Details

#each_declaration_type_name(names, decl, &block) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rbs/source.rb', line 76

def each_declaration_type_name(names, decl, &block)
  case decl
  when AST::Ruby::Declarations::ClassDecl
    decl.each_decl do |d|
      each_declaration_type_name(names, d, &block)
    end
    type_name = decl.class_name
  when AST::Ruby::Declarations::ModuleDecl
    decl.each_decl do |d|
      each_declaration_type_name(names, d, &block)
    end
    type_name = decl.module_name
  end

  if type_name
    unless names.include?(type_name)
      yield type_name
      names << type_name
    end
  end
end

#each_type_name(&block) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/rbs/source.rb', line 65

def each_type_name(&block)
  if block
    names = Set[] #: Set[TypeName]
    declarations.each do |decl|
      each_declaration_type_name(names, decl, &block)
    end
  else
    enum_for :each_type_name
  end
end