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, #pretty_print, #to_json
Constructor Details
#initialize(constant:, bodystmt:, location:) ⇒ ModuleDeclaration
Returns a new instance of ModuleDeclaration.
7672 7673 7674 7675 7676 7677 |
# File 'lib/syntax_tree/node.rb', line 7672 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
7667 7668 7669 |
# File 'lib/syntax_tree/node.rb', line 7667 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7670 7671 7672 |
# File 'lib/syntax_tree/node.rb', line 7670 def comments @comments end |
#constant ⇒ Object (readonly)
- ConstPathRef | ConstRef | TopConstRef
-
the name of the module
7664 7665 7666 |
# File 'lib/syntax_tree/node.rb', line 7664 def constant @constant end |
Instance Method Details
#===(other) ⇒ Object
7732 7733 7734 7735 |
# File 'lib/syntax_tree/node.rb', line 7732 def ===(other) other.is_a?(ModuleDeclaration) && constant === other.constant && bodystmt === other.bodystmt end |
#accept(visitor) ⇒ Object
7679 7680 7681 |
# File 'lib/syntax_tree/node.rb', line 7679 def accept(visitor) visitor.visit_module(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7683 7684 7685 |
# File 'lib/syntax_tree/node.rb', line 7683 def child_nodes [constant, bodystmt] end |
#copy(constant: nil, bodystmt: nil, location: nil) ⇒ Object
7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 |
# File 'lib/syntax_tree/node.rb', line 7687 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
7701 7702 7703 7704 7705 7706 7707 7708 |
# File 'lib/syntax_tree/node.rb', line 7701 def deconstruct_keys(_keys) { constant: constant, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 |
# File 'lib/syntax_tree/node.rb', line 7710 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 |