Class: RBS::AST::Declarations::Module

Inherits:
Object
  • Object
show all
Includes:
ShimTypeParams
Defined in:
lib/syntax_tree/rbs/declarations.rb

Instance Method Summary collapse

Methods included from ShimTypeParams

#type_params

Instance Method Details

#format(q) ⇒ Object

Prints out a module declaration, which looks like: module Foo end



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/syntax_tree/rbs/declarations.rb', line 178

def format(q)
  SyntaxTree::RBS::Comment.maybe_format(q, comment)
  SyntaxTree::RBS::Annotations.maybe_format(q, annotations)

  q.group do
    q.text("module ")
    SyntaxTree::RBS::NameAndTypeParams.new(self).format(q)

    if self_types.any?
      q.text(" : ")
      q.seplist(self_types, -> { q.text(", ") }) do |self_type|
        SyntaxTree::RBS::NameAndArgs.new(self_type).format(q)
      end
    end

    q.indent { SyntaxTree::RBS::Members.new(self).format(q) }
    q.breakable(force: true)
    q.text("end")
  end
end

#pretty_print(q) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/syntax_tree/rbs/declarations.rb', line 199

def pretty_print(q)
  q.group(2, "(module", ")") do
    SyntaxTree::RBS::Comment.maybe_pretty_print(q, comment)
    SyntaxTree::RBS::Annotations.maybe_pretty_print(q, annotations)

    q.pp(SyntaxTree::RBS::NameAndTypeParams.new(self))

    if self_types.any?
      q.breakable
      q.text("self_types=")
      q.group(2, "[", "]") do
        q.seplist(self_types) do |self_type|
          q.group(2, "(self-type", ")") do
            q.pp(SyntaxTree::RBS::NameAndArgs.new(self_type))
          end
        end
      end
    end

    q.breakable
    q.text("members=")
    q.pp(members)
  end
end