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.
7804 7805 7806 7807 7808 7809 |
# File 'lib/syntax_tree/node.rb', line 7804 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
7799 7800 7801 |
# File 'lib/syntax_tree/node.rb', line 7799 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7802 7803 7804 |
# File 'lib/syntax_tree/node.rb', line 7802 def comments @comments end |
#constant ⇒ Object (readonly)
- ConstPathRef | ConstRef | TopConstRef
-
the name of the module
7796 7797 7798 |
# File 'lib/syntax_tree/node.rb', line 7796 def constant @constant end |
Instance Method Details
#===(other) ⇒ Object
7864 7865 7866 7867 |
# File 'lib/syntax_tree/node.rb', line 7864 def ===(other) other.is_a?(ModuleDeclaration) && constant === other.constant && bodystmt === other.bodystmt end |
#accept(visitor) ⇒ Object
7811 7812 7813 |
# File 'lib/syntax_tree/node.rb', line 7811 def accept(visitor) visitor.visit_module(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7815 7816 7817 |
# File 'lib/syntax_tree/node.rb', line 7815 def child_nodes [constant, bodystmt] end |
#copy(constant: nil, bodystmt: nil, location: nil) ⇒ Object
7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 |
# File 'lib/syntax_tree/node.rb', line 7819 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
7833 7834 7835 7836 7837 7838 7839 7840 |
# File 'lib/syntax_tree/node.rb', line 7833 def deconstruct_keys(_keys) { constant: constant, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 |
# File 'lib/syntax_tree/node.rb', line 7842 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 |