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: StatementsNode | BeginNode | nil.
-
#constant_path ⇒ Object
readonly
attr_reader constant_path: ConstantReadNode | ConstantPathNode | MissingNode.
-
#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.
-
#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: ConstantReadNode | ConstantPathNode | MissingNode, ?body: StatementsNode | BeginNode | nil, ?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.
-
#save_end_keyword_loc(repository) ⇒ Object
Save the end_keyword_loc location using the given saved source so that it can be retrieved later.
-
#save_module_keyword_loc(repository) ⇒ Object
Save the module_keyword_loc location using the given saved source so that it can be retrieved later.
-
#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.
13070 13071 13072 13073 13074 13075 13076 13077 13078 13079 13080 13081 |
# File 'lib/prism/node.rb', line 13070 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: StatementsNode | BeginNode | nil
13139 13140 13141 |
# File 'lib/prism/node.rb', line 13139 def body @body end |
#constant_path ⇒ Object (readonly)
attr_reader constant_path: ConstantReadNode | ConstantPathNode | MissingNode
13136 13137 13138 |
# File 'lib/prism/node.rb', line 13136 def constant_path @constant_path end |
#locals ⇒ Object (readonly)
attr_reader locals: Array
13120 13121 13122 |
# File 'lib/prism/node.rb', line 13120 def locals @locals end |
#name ⇒ Object (readonly)
attr_reader name: Symbol
13155 13156 13157 |
# File 'lib/prism/node.rb', line 13155 def name @name end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
13178 13179 13180 |
# File 'lib/prism/node.rb', line 13178 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.
13184 13185 13186 13187 13188 13189 13190 13191 13192 13193 |
# File 'lib/prism/node.rb', line 13184 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
13084 13085 13086 |
# File 'lib/prism/node.rb', line 13084 def accept(visitor) visitor.visit_module_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
13089 13090 13091 |
# File 'lib/prism/node.rb', line 13089 def child_nodes [constant_path, body] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
13102 13103 13104 |
# File 'lib/prism/node.rb', line 13102 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
13094 13095 13096 13097 13098 13099 |
# File 'lib/prism/node.rb', line 13094 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: ConstantReadNode | ConstantPathNode | MissingNode, ?body: StatementsNode | BeginNode | nil, ?end_keyword_loc: Location, ?name: Symbol) -> ModuleNode
13107 13108 13109 |
# File 'lib/prism/node.rb', line 13107 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
13115 13116 13117 |
# File 'lib/prism/node.rb', line 13115 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
13163 13164 13165 |
# File 'lib/prism/node.rb', line 13163 def end_keyword end_keyword_loc.slice end |
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location
13142 13143 13144 13145 13146 |
# File 'lib/prism/node.rb', line 13142 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
13168 13169 13170 |
# File 'lib/prism/node.rb', line 13168 def inspect InspectVisitor.compose(self) end |
#module_keyword ⇒ Object
def module_keyword: () -> String
13158 13159 13160 |
# File 'lib/prism/node.rb', line 13158 def module_keyword module_keyword_loc.slice end |
#module_keyword_loc ⇒ Object
attr_reader module_keyword_loc: Location
13123 13124 13125 13126 13127 |
# File 'lib/prism/node.rb', line 13123 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 |
#save_end_keyword_loc(repository) ⇒ Object
Save the end_keyword_loc location using the given saved source so that it can be retrieved later.
13150 13151 13152 |
# File 'lib/prism/node.rb', line 13150 def save_end_keyword_loc(repository) repository.enter(node_id, :end_keyword_loc) end |
#save_module_keyword_loc(repository) ⇒ Object
Save the module_keyword_loc location using the given saved source so that it can be retrieved later.
13131 13132 13133 |
# File 'lib/prism/node.rb', line 13131 def save_module_keyword_loc(repository) repository.enter(node_id, :module_keyword_loc) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
13173 13174 13175 |
# File 'lib/prism/node.rb', line 13173 def type :module_node end |