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
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(constant: nil, bodystmt: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(constant:, bodystmt:, location:) ⇒ ModuleDeclaration
constructor
A new instance of ModuleDeclaration.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(constant:, bodystmt:, location:) ⇒ ModuleDeclaration
Returns a new instance of ModuleDeclaration.
7789 7790 7791 7792 7793 7794 |
# File 'lib/syntax_tree/node.rb', line 7789 def initialize(constant:, bodystmt:, location:) @constant = constant @bodystmt = bodystmt @location = location @comments = [] end |
Instance Attribute Details
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the expressions to be executed in the context of the module
7784 7785 7786 |
# File 'lib/syntax_tree/node.rb', line 7784 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7787 7788 7789 |
# File 'lib/syntax_tree/node.rb', line 7787 def comments @comments end |
#constant ⇒ Object (readonly)
- ConstPathRef | ConstRef | TopConstRef
-
the name of the module
7781 7782 7783 |
# File 'lib/syntax_tree/node.rb', line 7781 def constant @constant end |
Instance Method Details
#===(other) ⇒ Object
7849 7850 7851 7852 |
# File 'lib/syntax_tree/node.rb', line 7849 def ===(other) other.is_a?(ModuleDeclaration) && constant === other.constant && bodystmt === other.bodystmt end |
#accept(visitor) ⇒ Object
7796 7797 7798 |
# File 'lib/syntax_tree/node.rb', line 7796 def accept(visitor) visitor.visit_module(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7800 7801 7802 |
# File 'lib/syntax_tree/node.rb', line 7800 def child_nodes [constant, bodystmt] end |
#copy(constant: nil, bodystmt: nil, location: nil) ⇒ Object
7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 |
# File 'lib/syntax_tree/node.rb', line 7804 def copy(constant: nil, bodystmt: nil, location: nil) node = ModuleDeclaration.new( constant: constant || self.constant, bodystmt: bodystmt || self.bodystmt, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
7818 7819 7820 7821 7822 7823 7824 7825 |
# File 'lib/syntax_tree/node.rb', line 7818 def deconstruct_keys(_keys) { constant: constant, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 |
# File 'lib/syntax_tree/node.rb', line 7827 def format(q) if bodystmt.empty? q.group do format_declaration(q) q.breakable_force q.text("end") end else q.group do format_declaration(q) q.indent do q.breakable_force q.format(bodystmt) end q.breakable_force q.text("end") end end end |