Class: SyntaxTree::ModuleDeclaration
- Defined in:
- lib/syntax_tree/node.rb
Overview
ModuleDeclaration represents defining a module using the module keyword.
module Namespace
end
Instance Attribute Summary collapse
-
#bodystmt ⇒ Object
readonly
- BodyStmt
-
the expressions to be executed in the context of the module.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#constant ⇒ Object
readonly
- ConstPathRef | ConstRef | TopConstRef
-
the name of the module.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(constant:, bodystmt:, location:, comments: []) ⇒ ModuleDeclaration
constructor
A new instance of ModuleDeclaration.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(constant:, bodystmt:, location:, comments: []) ⇒ ModuleDeclaration
Returns a new instance of ModuleDeclaration.
6363 6364 6365 6366 6367 6368 |
# File 'lib/syntax_tree/node.rb', line 6363 def initialize(constant:, bodystmt:, location:, comments: []) @constant = constant @bodystmt = bodystmt @location = location @comments = comments end |
Instance Attribute Details
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the expressions to be executed in the context of the module
6358 6359 6360 |
# File 'lib/syntax_tree/node.rb', line 6358 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6361 6362 6363 |
# File 'lib/syntax_tree/node.rb', line 6361 def comments @comments end |
#constant ⇒ Object (readonly)
- ConstPathRef | ConstRef | TopConstRef
-
the name of the module
6355 6356 6357 |
# File 'lib/syntax_tree/node.rb', line 6355 def constant @constant end |
Instance Method Details
#accept(visitor) ⇒ Object
6370 6371 6372 |
# File 'lib/syntax_tree/node.rb', line 6370 def accept(visitor) visitor.visit_module(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6374 6375 6376 |
# File 'lib/syntax_tree/node.rb', line 6374 def child_nodes [constant, bodystmt] end |
#deconstruct_keys(_keys) ⇒ Object
6380 6381 6382 6383 6384 6385 6386 6387 |
# File 'lib/syntax_tree/node.rb', line 6380 def deconstruct_keys(_keys) { constant: constant, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 |
# File 'lib/syntax_tree/node.rb', line 6389 def format(q) declaration = -> do q.group do q.text("module ") q.format(constant) end end if bodystmt.empty? q.group do declaration.call q.breakable(force: true) q.text("end") end else q.group do declaration.call q.indent do q.breakable(force: true) q.format(bodystmt) end q.breakable(force: true) q.text("end") end end end |