Class: SyntaxTree::ModuleDeclaration
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::ModuleDeclaration
show all
- 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
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(constant:, bodystmt:, location:) ⇒ ModuleDeclaration
7684
7685
7686
7687
7688
7689
|
# File 'lib/syntax_tree/node.rb', line 7684
def initialize(constant:, bodystmt:, location:)
@constant = constant
@bodystmt = bodystmt
@location = location
= []
end
|
Instance Attribute Details
#bodystmt ⇒ Object
- BodyStmt
-
the expressions to be executed in the context of the module
7679
7680
7681
|
# File 'lib/syntax_tree/node.rb', line 7679
def bodystmt
@bodystmt
end
|
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7682
7683
7684
|
# File 'lib/syntax_tree/node.rb', line 7682
def
end
|
#constant ⇒ Object
- ConstPathRef | ConstRef | TopConstRef
-
the name of the module
7676
7677
7678
|
# File 'lib/syntax_tree/node.rb', line 7676
def constant
@constant
end
|
Instance Method Details
#===(other) ⇒ Object
7744
7745
7746
7747
|
# File 'lib/syntax_tree/node.rb', line 7744
def ===(other)
other.is_a?(ModuleDeclaration) && constant === other.constant &&
bodystmt === other.bodystmt
end
|
#accept(visitor) ⇒ Object
7691
7692
7693
|
# File 'lib/syntax_tree/node.rb', line 7691
def accept(visitor)
visitor.visit_module(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
7695
7696
7697
|
# File 'lib/syntax_tree/node.rb', line 7695
def child_nodes
[constant, bodystmt]
end
|
#copy(constant: nil, bodystmt: nil, location: nil) ⇒ Object
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
|
# File 'lib/syntax_tree/node.rb', line 7699
def copy(constant: nil, bodystmt: nil, location: nil)
node =
ModuleDeclaration.new(
constant: constant || self.constant,
bodystmt: bodystmt || self.bodystmt,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
7713
7714
7715
7716
7717
7718
7719
7720
|
# File 'lib/syntax_tree/node.rb', line 7713
def deconstruct_keys(_keys)
{
constant: constant,
bodystmt: bodystmt,
location: location,
comments:
}
end
|
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
|
# File 'lib/syntax_tree/node.rb', line 7722
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
|