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
Constructor Details
#initialize(constant:, bodystmt:, location:, comments: []) ⇒ ModuleDeclaration
Returns a new instance of ModuleDeclaration.
6194 6195 6196 6197 6198 6199 |
# File 'lib/syntax_tree/node.rb', line 6194 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
6189 6190 6191 |
# File 'lib/syntax_tree/node.rb', line 6189 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6192 6193 6194 |
# File 'lib/syntax_tree/node.rb', line 6192 def comments @comments end |
#constant ⇒ Object (readonly)
- ConstPathRef | ConstRef | TopConstRef
-
the name of the module
6186 6187 6188 |
# File 'lib/syntax_tree/node.rb', line 6186 def constant @constant end |
Instance Method Details
#accept(visitor) ⇒ Object
6201 6202 6203 |
# File 'lib/syntax_tree/node.rb', line 6201 def accept(visitor) visitor.visit_module(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
6205 6206 6207 |
# File 'lib/syntax_tree/node.rb', line 6205 def child_nodes [constant, bodystmt] end |
#deconstruct_keys(keys) ⇒ Object
6211 6212 6213 6214 6215 6216 6217 6218 |
# File 'lib/syntax_tree/node.rb', line 6211 def deconstruct_keys(keys) { constant: constant, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 |
# File 'lib/syntax_tree/node.rb', line 6220 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 |