Class: SyntaxTree::ModuleDeclaration
- Inherits:
-
Object
- Object
- SyntaxTree::ModuleDeclaration
- Defined in:
- lib/syntax_tree.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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(constant:, bodystmt:, location:, comments: []) ⇒ ModuleDeclaration
constructor
A new instance of ModuleDeclaration.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(constant:, bodystmt:, location:, comments: []) ⇒ ModuleDeclaration
Returns a new instance of ModuleDeclaration.
8542 8543 8544 8545 8546 8547 |
# File 'lib/syntax_tree.rb', line 8542 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
8534 8535 8536 |
# File 'lib/syntax_tree.rb', line 8534 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8540 8541 8542 |
# File 'lib/syntax_tree.rb', line 8540 def comments @comments end |
#constant ⇒ Object (readonly)
- ConstPathRef | ConstRef | TopConstRef
-
the name of the module
8531 8532 8533 |
# File 'lib/syntax_tree.rb', line 8531 def constant @constant end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
8537 8538 8539 |
# File 'lib/syntax_tree.rb', line 8537 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
8549 8550 8551 |
# File 'lib/syntax_tree.rb', line 8549 def child_nodes [constant, bodystmt] end |
#format(q) ⇒ Object
8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 |
# File 'lib/syntax_tree.rb', line 8553 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 |
#pretty_print(q) ⇒ Object
8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 |
# File 'lib/syntax_tree.rb', line 8582 def pretty_print(q) q.group(2, "(", ")") do q.text("module") q.breakable q.pp(constant) q.breakable q.pp(bodystmt) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
8596 8597 8598 8599 8600 8601 8602 8603 8604 |
# File 'lib/syntax_tree.rb', line 8596 def to_json(*opts) { type: :module, constant: constant, bodystmt: bodystmt, loc: location, cmts: comments }.to_json(*opts) end |