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: Prism::node?.
-
#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: Prism::node?, ?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: Prism::node?, 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.
5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 |
# File 'lib/prism/node.rb', line 5102 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: Prism::node?
5175 5176 5177 |
# File 'lib/prism/node.rb', line 5175 def body @body end |
#locals ⇒ Object (readonly)
attr_reader locals: Array
5178 5179 5180 |
# File 'lib/prism/node.rb', line 5178 def locals @locals end |
#name ⇒ Object (readonly)
attr_reader name: Symbol
5159 5160 5161 |
# File 'lib/prism/node.rb', line 5159 def name @name end |
#parameters ⇒ Object (readonly)
attr_reader parameters: ParametersNode?
5172 5173 5174 |
# File 'lib/prism/node.rb', line 5172 def parameters @parameters end |
#receiver ⇒ Object (readonly)
attr_reader receiver: Prism::node?
5169 5170 5171 |
# File 'lib/prism/node.rb', line 5169 def receiver @receiver end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
5293 5294 5295 |
# File 'lib/prism/node.rb', line 5293 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.
5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 |
# File 'lib/prism/node.rb', line 5299 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
5122 5123 5124 |
# File 'lib/prism/node.rb', line 5122 def accept(visitor) visitor.visit_def_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
5127 5128 5129 |
# File 'lib/prism/node.rb', line 5127 def child_nodes [receiver, parameters, body] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
5141 5142 5143 |
# File 'lib/prism/node.rb', line 5141 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
5132 5133 5134 5135 5136 5137 5138 |
# File 'lib/prism/node.rb', line 5132 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: Prism::node?, ?locals: Array, ?def_keyword_loc: Location, ?operator_loc: Location?, ?lparen_loc: Location?, ?rparen_loc: Location?, ?equal_loc: Location?, ?end_keyword_loc: Location?) -> DefNode
5146 5147 5148 |
# File 'lib/prism/node.rb', line 5146 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: Prism::node?, locals: Array, def_keyword_loc: Location, operator_loc: Location?, lparen_loc: Location?, rparen_loc: Location?, equal_loc: Location?, end_keyword_loc: Location? }
5154 5155 5156 |
# File 'lib/prism/node.rb', line 5154 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
5253 5254 5255 |
# File 'lib/prism/node.rb', line 5253 def def_keyword def_keyword_loc.slice end |
#def_keyword_loc ⇒ Object
attr_reader def_keyword_loc: Location
5181 5182 5183 5184 5185 |
# File 'lib/prism/node.rb', line 5181 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?
5278 5279 5280 |
# File 'lib/prism/node.rb', line 5278 def end_keyword end_keyword_loc&.slice end |
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location?
5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 |
# File 'lib/prism/node.rb', line 5240 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?
5273 5274 5275 |
# File 'lib/prism/node.rb', line 5273 def equal equal_loc&.slice end |
#equal_loc ⇒ Object
attr_reader equal_loc: Location?
5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 |
# File 'lib/prism/node.rb', line 5227 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
5283 5284 5285 |
# File 'lib/prism/node.rb', line 5283 def inspect InspectVisitor.compose(self) end |
#lparen ⇒ Object
def lparen: () -> String?
5263 5264 5265 |
# File 'lib/prism/node.rb', line 5263 def lparen lparen_loc&.slice end |
#lparen_loc ⇒ Object
attr_reader lparen_loc: Location?
5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 |
# File 'lib/prism/node.rb', line 5201 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
5162 5163 5164 5165 5166 |
# File 'lib/prism/node.rb', line 5162 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?
5258 5259 5260 |
# File 'lib/prism/node.rb', line 5258 def operator operator_loc&.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location?
5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 |
# File 'lib/prism/node.rb', line 5188 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?
5268 5269 5270 |
# File 'lib/prism/node.rb', line 5268 def rparen rparen_loc&.slice end |
#rparen_loc ⇒ Object
attr_reader rparen_loc: Location?
5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 |
# File 'lib/prism/node.rb', line 5214 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`.
5288 5289 5290 |
# File 'lib/prism/node.rb', line 5288 def type :def_node end |