Class: Prism::DefNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::DefNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a method definition.
def method
end
^^^^^^^^^^
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
attr_reader body: StatementsNode | BeginNode | nil.
-
#locals ⇒ Object
readonly
attr_reader locals: Array.
-
#name ⇒ Object
readonly
attr_reader name: Symbol.
-
#parameters ⇒ Object
readonly
attr_reader parameters: ParametersNode?.
-
#receiver ⇒ Object
readonly
attr_reader receiver: Prism::node?.
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, name: self.name, name_loc: self.name_loc, receiver: self.receiver, parameters: self.parameters, body: self.body, locals: self.locals, def_keyword_loc: self.def_keyword_loc, operator_loc: self.operator_loc, lparen_loc: self.lparen_loc, rparen_loc: self.rparen_loc, equal_loc: self.equal_loc, end_keyword_loc: self.end_keyword_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?receiver: Prism::node?, ?parameters: ParametersNode?, ?body: StatementsNode | BeginNode | nil, ?locals: Array, ?def_keyword_loc: Location, ?operator_loc: Location?, ?lparen_loc: Location?, ?rparen_loc: Location?, ?equal_loc: Location?, ?end_keyword_loc: Location?) -> DefNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, receiver: Prism::node?, parameters: ParametersNode?, body: StatementsNode | BeginNode | nil, locals: Array, def_keyword_loc: Location, operator_loc: Location?, lparen_loc: Location?, rparen_loc: Location?, equal_loc: Location?, end_keyword_loc: Location? }.
-
#def_keyword ⇒ Object
def def_keyword: () -> String.
-
#def_keyword_loc ⇒ Object
attr_reader def_keyword_loc: Location.
-
#end_keyword ⇒ Object
def end_keyword: () -> String?.
-
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location?.
-
#equal ⇒ Object
def equal: () -> String?.
-
#equal_loc ⇒ Object
attr_reader equal_loc: Location?.
-
#initialize(source, node_id, location, flags, name, name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc) ⇒ DefNode
constructor
Initialize a new DefNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#lparen ⇒ Object
def lparen: () -> String?.
-
#lparen_loc ⇒ Object
attr_reader lparen_loc: Location?.
-
#name_loc ⇒ Object
attr_reader name_loc: Location.
-
#operator ⇒ Object
def operator: () -> String?.
-
#operator_loc ⇒ Object
attr_reader operator_loc: Location?.
-
#rparen ⇒ Object
def rparen: () -> String?.
-
#rparen_loc ⇒ Object
attr_reader rparen_loc: Location?.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, name, name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc) ⇒ DefNode
Initialize a new DefNode node.
5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 |
# File 'lib/prism/node.rb', line 5139 def initialize(source, node_id, location, flags, name, name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc) @source = source @node_id = node_id @location = location @flags = flags @name = name @name_loc = name_loc @receiver = receiver @parameters = parameters @body = body @locals = locals @def_keyword_loc = def_keyword_loc @operator_loc = operator_loc @lparen_loc = lparen_loc @rparen_loc = rparen_loc @equal_loc = equal_loc @end_keyword_loc = end_keyword_loc end |
Instance Attribute Details
#body ⇒ Object (readonly)
attr_reader body: StatementsNode | BeginNode | nil
5212 5213 5214 |
# File 'lib/prism/node.rb', line 5212 def body @body end |
#locals ⇒ Object (readonly)
attr_reader locals: Array
5215 5216 5217 |
# File 'lib/prism/node.rb', line 5215 def locals @locals end |
#name ⇒ Object (readonly)
attr_reader name: Symbol
5196 5197 5198 |
# File 'lib/prism/node.rb', line 5196 def name @name end |
#parameters ⇒ Object (readonly)
attr_reader parameters: ParametersNode?
5209 5210 5211 |
# File 'lib/prism/node.rb', line 5209 def parameters @parameters end |
#receiver ⇒ Object (readonly)
attr_reader receiver: Prism::node?
5206 5207 5208 |
# File 'lib/prism/node.rb', line 5206 def receiver @receiver end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
5330 5331 5332 |
# File 'lib/prism/node.rb', line 5330 def self.type :def_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.
5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 |
# File 'lib/prism/node.rb', line 5336 def ===(other) other.is_a?(DefNode) && (name === other.name) && (name_loc.nil? == other.name_loc.nil?) && (receiver === other.receiver) && (parameters === other.parameters) && (body === other.body) && (locals.length == other.locals.length) && locals.zip(other.locals).all? { |left, right| left === right } && (def_keyword_loc.nil? == other.def_keyword_loc.nil?) && (operator_loc.nil? == other.operator_loc.nil?) && (lparen_loc.nil? == other.lparen_loc.nil?) && (rparen_loc.nil? == other.rparen_loc.nil?) && (equal_loc.nil? == other.equal_loc.nil?) && (end_keyword_loc.nil? == other.end_keyword_loc.nil?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
5159 5160 5161 |
# File 'lib/prism/node.rb', line 5159 def accept(visitor) visitor.visit_def_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
5164 5165 5166 |
# File 'lib/prism/node.rb', line 5164 def child_nodes [receiver, parameters, body] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
5178 5179 5180 |
# File 'lib/prism/node.rb', line 5178 def comment_targets [name_loc, *receiver, *parameters, *body, def_keyword_loc, *operator_loc, *lparen_loc, *rparen_loc, *equal_loc, *end_keyword_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
5169 5170 5171 5172 5173 5174 5175 |
# File 'lib/prism/node.rb', line 5169 def compact_child_nodes compact = [] #: Array[Prism::node] compact << receiver if receiver compact << parameters if parameters compact << body if body compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, receiver: self.receiver, parameters: self.parameters, body: self.body, locals: self.locals, def_keyword_loc: self.def_keyword_loc, operator_loc: self.operator_loc, lparen_loc: self.lparen_loc, rparen_loc: self.rparen_loc, equal_loc: self.equal_loc, end_keyword_loc: self.end_keyword_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol, ?name_loc: Location, ?receiver: Prism::node?, ?parameters: ParametersNode?, ?body: StatementsNode | BeginNode | nil, ?locals: Array, ?def_keyword_loc: Location, ?operator_loc: Location?, ?lparen_loc: Location?, ?rparen_loc: Location?, ?equal_loc: Location?, ?end_keyword_loc: Location?) -> DefNode
5183 5184 5185 |
# File 'lib/prism/node.rb', line 5183 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, receiver: self.receiver, parameters: self.parameters, body: self.body, locals: self.locals, def_keyword_loc: self.def_keyword_loc, operator_loc: self.operator_loc, lparen_loc: self.lparen_loc, rparen_loc: self.rparen_loc, equal_loc: self.equal_loc, end_keyword_loc: self.end_keyword_loc) DefNode.new(source, node_id, location, flags, name, name_loc, receiver, parameters, body, locals, def_keyword_loc, operator_loc, lparen_loc, rparen_loc, equal_loc, end_keyword_loc) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol, name_loc: Location, receiver: Prism::node?, parameters: ParametersNode?, body: StatementsNode | BeginNode | nil, locals: Array, def_keyword_loc: Location, operator_loc: Location?, lparen_loc: Location?, rparen_loc: Location?, equal_loc: Location?, end_keyword_loc: Location? }
5191 5192 5193 |
# File 'lib/prism/node.rb', line 5191 def deconstruct_keys(keys) { node_id: node_id, location: location, name: name, name_loc: name_loc, receiver: receiver, parameters: parameters, body: body, locals: locals, def_keyword_loc: def_keyword_loc, operator_loc: operator_loc, lparen_loc: lparen_loc, rparen_loc: rparen_loc, equal_loc: equal_loc, end_keyword_loc: end_keyword_loc } end |
#def_keyword ⇒ Object
def def_keyword: () -> String
5290 5291 5292 |
# File 'lib/prism/node.rb', line 5290 def def_keyword def_keyword_loc.slice end |
#def_keyword_loc ⇒ Object
attr_reader def_keyword_loc: Location
5218 5219 5220 5221 5222 |
# File 'lib/prism/node.rb', line 5218 def def_keyword_loc location = @def_keyword_loc return location if location.is_a?(Location) @def_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#end_keyword ⇒ Object
def end_keyword: () -> String?
5315 5316 5317 |
# File 'lib/prism/node.rb', line 5315 def end_keyword end_keyword_loc&.slice end |
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location?
5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 |
# File 'lib/prism/node.rb', line 5277 def end_keyword_loc location = @end_keyword_loc case location when nil nil when Location location else @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#equal ⇒ Object
def equal: () -> String?
5310 5311 5312 |
# File 'lib/prism/node.rb', line 5310 def equal equal_loc&.slice end |
#equal_loc ⇒ Object
attr_reader equal_loc: Location?
5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 |
# File 'lib/prism/node.rb', line 5264 def equal_loc location = @equal_loc case location when nil nil when Location location else @equal_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#inspect ⇒ Object
def inspect -> String
5320 5321 5322 |
# File 'lib/prism/node.rb', line 5320 def inspect InspectVisitor.compose(self) end |
#lparen ⇒ Object
def lparen: () -> String?
5300 5301 5302 |
# File 'lib/prism/node.rb', line 5300 def lparen lparen_loc&.slice end |
#lparen_loc ⇒ Object
attr_reader lparen_loc: Location?
5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 |
# File 'lib/prism/node.rb', line 5238 def lparen_loc location = @lparen_loc case location when nil nil when Location location else @lparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#name_loc ⇒ Object
attr_reader name_loc: Location
5199 5200 5201 5202 5203 |
# File 'lib/prism/node.rb', line 5199 def name_loc location = @name_loc return location if location.is_a?(Location) @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#operator ⇒ Object
def operator: () -> String?
5295 5296 5297 |
# File 'lib/prism/node.rb', line 5295 def operator operator_loc&.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location?
5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 |
# File 'lib/prism/node.rb', line 5225 def operator_loc location = @operator_loc case location when nil nil when Location location else @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#rparen ⇒ Object
def rparen: () -> String?
5305 5306 5307 |
# File 'lib/prism/node.rb', line 5305 def rparen rparen_loc&.slice end |
#rparen_loc ⇒ Object
attr_reader rparen_loc: Location?
5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 |
# File 'lib/prism/node.rb', line 5251 def rparen_loc location = @rparen_loc case location when nil nil when Location location else @rparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
5325 5326 5327 |
# File 'lib/prism/node.rb', line 5325 def type :def_node end |