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.
5651 5652 5653 5654 5655 5656 |
# File 'lib/syntax_tree/node.rb', line 5651 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
5646 5647 5648 |
# File 'lib/syntax_tree/node.rb', line 5646 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
5649 5650 5651 |
# File 'lib/syntax_tree/node.rb', line 5649 def comments @comments end |
#constant ⇒ Object (readonly)
- ConstPathRef | ConstRef | TopConstRef
-
the name of the module
5643 5644 5645 |
# File 'lib/syntax_tree/node.rb', line 5643 def constant @constant end |
Instance Method Details
#accept(visitor) ⇒ Object
5658 5659 5660 |
# File 'lib/syntax_tree/node.rb', line 5658 def accept(visitor) visitor.visit_module(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
5662 5663 5664 |
# File 'lib/syntax_tree/node.rb', line 5662 def child_nodes [constant, bodystmt] end |
#deconstruct_keys(keys) ⇒ Object
5668 5669 5670 5671 5672 5673 5674 5675 |
# File 'lib/syntax_tree/node.rb', line 5668 def deconstruct_keys(keys) { constant: constant, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 |
# File 'lib/syntax_tree/node.rb', line 5677 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 |