Class: Prism::ModuleNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ModuleNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a module declaration involving the ‘module` keyword.
module Foo end
^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
attr_reader body: Prism::node?.
-
#constant_path ⇒ Object
readonly
attr_reader constant_path: Prism::node.
-
#locals ⇒ Object
readonly
attr_reader locals: Array.
-
#name ⇒ Object
readonly
attr_reader name: Symbol.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, module_keyword_loc: self.module_keyword_loc, constant_path: self.constant_path, body: self.body, end_keyword_loc: self.end_keyword_loc, name: self.name) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?module_keyword_loc: Location, ?constant_path: Prism::node, ?body: Prism::node?, ?end_keyword_loc: Location, ?name: Symbol) -> ModuleNode.
- #deconstruct_keys(keys) ⇒ Object
-
#end_keyword ⇒ Object
def end_keyword: () -> String.
-
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location.
-
#initialize(source, node_id, location, flags, locals, module_keyword_loc, constant_path, body, end_keyword_loc, name) ⇒ ModuleNode
constructor
Initialize a new ModuleNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#module_keyword ⇒ Object
def module_keyword: () -> String.
-
#module_keyword_loc ⇒ Object
attr_reader module_keyword_loc: Location.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, locals, module_keyword_loc, constant_path, body, end_keyword_loc, name) ⇒ ModuleNode
Initialize a new ModuleNode node.
11548 11549 11550 11551 11552 11553 11554 11555 11556 11557 11558 11559 |
# File 'lib/prism/node.rb', line 11548 def initialize(source, node_id, location, flags, locals, module_keyword_loc, constant_path, body, end_keyword_loc, name) @source = source @node_id = node_id @location = location @flags = flags @locals = locals @module_keyword_loc = module_keyword_loc @constant_path = constant_path @body = body @end_keyword_loc = end_keyword_loc @name = name end |
Instance Attribute Details
#body ⇒ Object (readonly)
attr_reader body: Prism::node?
11611 11612 11613 |
# File 'lib/prism/node.rb', line 11611 def body @body end |
#constant_path ⇒ Object (readonly)
attr_reader constant_path: Prism::node
11608 11609 11610 |
# File 'lib/prism/node.rb', line 11608 def constant_path @constant_path end |
#locals ⇒ Object (readonly)
attr_reader locals: Array
11598 11599 11600 |
# File 'lib/prism/node.rb', line 11598 def locals @locals end |
#name ⇒ Object (readonly)
attr_reader name: Symbol
11621 11622 11623 |
# File 'lib/prism/node.rb', line 11621 def name @name end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
11644 11645 11646 |
# File 'lib/prism/node.rb', line 11644 def self.type :module_node end |
Instance Method Details
#===(other) ⇒ Object
Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.
11650 11651 11652 11653 11654 11655 11656 11657 11658 11659 |
# File 'lib/prism/node.rb', line 11650 def ===(other) other.is_a?(ModuleNode) && (locals.length == other.locals.length) && locals.zip(other.locals).all? { |left, right| left === right } && (module_keyword_loc.nil? == other.module_keyword_loc.nil?) && (constant_path === other.constant_path) && (body === other.body) && (end_keyword_loc.nil? == other.end_keyword_loc.nil?) && (name === other.name) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
11562 11563 11564 |
# File 'lib/prism/node.rb', line 11562 def accept(visitor) visitor.visit_module_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
11567 11568 11569 |
# File 'lib/prism/node.rb', line 11567 def child_nodes [constant_path, body] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
11580 11581 11582 |
# File 'lib/prism/node.rb', line 11580 def comment_targets [module_keyword_loc, constant_path, *body, end_keyword_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
11572 11573 11574 11575 11576 11577 |
# File 'lib/prism/node.rb', line 11572 def compact_child_nodes compact = [] #: Array[Prism::node] compact << constant_path compact << body if body compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, module_keyword_loc: self.module_keyword_loc, constant_path: self.constant_path, body: self.body, end_keyword_loc: self.end_keyword_loc, name: self.name) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?module_keyword_loc: Location, ?constant_path: Prism::node, ?body: Prism::node?, ?end_keyword_loc: Location, ?name: Symbol) -> ModuleNode
11585 11586 11587 |
# File 'lib/prism/node.rb', line 11585 def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, module_keyword_loc: self.module_keyword_loc, constant_path: self.constant_path, body: self.body, end_keyword_loc: self.end_keyword_loc, name: self.name) ModuleNode.new(source, node_id, location, flags, locals, module_keyword_loc, constant_path, body, end_keyword_loc, name) end |
#deconstruct_keys(keys) ⇒ Object
11593 11594 11595 |
# File 'lib/prism/node.rb', line 11593 def deconstruct_keys(keys) { node_id: node_id, location: location, locals: locals, module_keyword_loc: module_keyword_loc, constant_path: constant_path, body: body, end_keyword_loc: end_keyword_loc, name: name } end |
#end_keyword ⇒ Object
def end_keyword: () -> String
11629 11630 11631 |
# File 'lib/prism/node.rb', line 11629 def end_keyword end_keyword_loc.slice end |
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location
11614 11615 11616 11617 11618 |
# File 'lib/prism/node.rb', line 11614 def end_keyword_loc location = @end_keyword_loc return location if location.is_a?(Location) @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#inspect ⇒ Object
def inspect -> String
11634 11635 11636 |
# File 'lib/prism/node.rb', line 11634 def inspect InspectVisitor.compose(self) end |
#module_keyword ⇒ Object
def module_keyword: () -> String
11624 11625 11626 |
# File 'lib/prism/node.rb', line 11624 def module_keyword module_keyword_loc.slice end |
#module_keyword_loc ⇒ Object
attr_reader module_keyword_loc: Location
11601 11602 11603 11604 11605 |
# File 'lib/prism/node.rb', line 11601 def module_keyword_loc location = @module_keyword_loc return location if location.is_a?(Location) @module_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
11639 11640 11641 |
# File 'lib/prism/node.rb', line 11639 def type :module_node end |