Class: Prism::LambdaNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::LambdaNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents using a lambda literal (not the lambda method call).
->(value) { value * 2 }
^^^^^^^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
attr_reader body: Prism::node?.
-
#locals ⇒ Object
readonly
attr_reader locals: Array.
-
#parameters ⇒ Object
readonly
attr_reader parameters: 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].
-
#closing ⇒ Object
def closing: () -> String.
-
#closing_loc ⇒ Object
attr_reader closing_loc: Location.
-
#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, operator_loc: self.operator_loc, opening_loc: self.opening_loc, closing_loc: self.closing_loc, parameters: self.parameters, body: self.body) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?operator_loc: Location, ?opening_loc: Location, ?closing_loc: Location, ?parameters: Prism::node?, ?body: Prism::node?) -> LambdaNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(source, node_id, location, flags, locals, operator_loc, opening_loc, closing_loc, parameters, body) ⇒ LambdaNode
constructor
Initialize a new LambdaNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#opening ⇒ Object
def opening: () -> String.
-
#opening_loc ⇒ Object
attr_reader opening_loc: Location.
-
#operator ⇒ Object
def operator: () -> String.
-
#operator_loc ⇒ Object
attr_reader operator_loc: Location.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, locals, operator_loc, opening_loc, closing_loc, parameters, body) ⇒ LambdaNode
Initialize a new LambdaNode node.
10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 |
# File 'lib/prism/node.rb', line 10300 def initialize(source, node_id, location, flags, locals, operator_loc, opening_loc, closing_loc, parameters, body) @source = source @node_id = node_id @location = location @flags = flags @locals = locals @operator_loc = operator_loc @opening_loc = opening_loc @closing_loc = closing_loc @parameters = parameters @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
attr_reader body: Prism::node?
10377 10378 10379 |
# File 'lib/prism/node.rb', line 10377 def body @body end |
#locals ⇒ Object (readonly)
attr_reader locals: Array
10350 10351 10352 |
# File 'lib/prism/node.rb', line 10350 def locals @locals end |
#parameters ⇒ Object (readonly)
attr_reader parameters: Prism::node?
10374 10375 10376 |
# File 'lib/prism/node.rb', line 10374 def parameters @parameters end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
10405 10406 10407 |
# File 'lib/prism/node.rb', line 10405 def self.type :lambda_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.
10411 10412 10413 10414 10415 10416 10417 10418 10419 10420 |
# File 'lib/prism/node.rb', line 10411 def ===(other) other.is_a?(LambdaNode) && (locals.length == other.locals.length) && locals.zip(other.locals).all? { |left, right| left === right } && (operator_loc.nil? == other.operator_loc.nil?) && (opening_loc.nil? == other.opening_loc.nil?) && (closing_loc.nil? == other.closing_loc.nil?) && (parameters === other.parameters) && (body === other.body) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
10314 10315 10316 |
# File 'lib/prism/node.rb', line 10314 def accept(visitor) visitor.visit_lambda_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
10319 10320 10321 |
# File 'lib/prism/node.rb', line 10319 def child_nodes [parameters, body] end |
#closing ⇒ Object
def closing: () -> String
10390 10391 10392 |
# File 'lib/prism/node.rb', line 10390 def closing closing_loc.slice end |
#closing_loc ⇒ Object
attr_reader closing_loc: Location
10367 10368 10369 10370 10371 |
# File 'lib/prism/node.rb', line 10367 def closing_loc location = @closing_loc return location if location.is_a?(Location) @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
10332 10333 10334 |
# File 'lib/prism/node.rb', line 10332 def comment_targets [operator_loc, opening_loc, closing_loc, *parameters, *body] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
10324 10325 10326 10327 10328 10329 |
# File 'lib/prism/node.rb', line 10324 def compact_child_nodes compact = [] #: Array[Prism::node] compact << parameters if parameters compact << body if body compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, operator_loc: self.operator_loc, opening_loc: self.opening_loc, closing_loc: self.closing_loc, parameters: self.parameters, body: self.body) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?operator_loc: Location, ?opening_loc: Location, ?closing_loc: Location, ?parameters: Prism::node?, ?body: Prism::node?) -> LambdaNode
10337 10338 10339 |
# File 'lib/prism/node.rb', line 10337 def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, operator_loc: self.operator_loc, opening_loc: self.opening_loc, closing_loc: self.closing_loc, parameters: self.parameters, body: self.body) LambdaNode.new(source, node_id, location, flags, locals, operator_loc, opening_loc, closing_loc, parameters, body) end |
#deconstruct_keys(keys) ⇒ Object
10345 10346 10347 |
# File 'lib/prism/node.rb', line 10345 def deconstruct_keys(keys) { node_id: node_id, location: location, locals: locals, operator_loc: operator_loc, opening_loc: opening_loc, closing_loc: closing_loc, parameters: parameters, body: body } end |
#inspect ⇒ Object
def inspect -> String
10395 10396 10397 |
# File 'lib/prism/node.rb', line 10395 def inspect InspectVisitor.compose(self) end |
#opening ⇒ Object
def opening: () -> String
10385 10386 10387 |
# File 'lib/prism/node.rb', line 10385 def opening opening_loc.slice end |
#opening_loc ⇒ Object
attr_reader opening_loc: Location
10360 10361 10362 10363 10364 |
# File 'lib/prism/node.rb', line 10360 def opening_loc location = @opening_loc return location if location.is_a?(Location) @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#operator ⇒ Object
def operator: () -> String
10380 10381 10382 |
# File 'lib/prism/node.rb', line 10380 def operator operator_loc.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location
10353 10354 10355 10356 10357 |
# File 'lib/prism/node.rb', line 10353 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
10400 10401 10402 |
# File 'lib/prism/node.rb', line 10400 def type :lambda_node end |