class Prism::LambdaNode
Represents using a lambda literal (not the lambda method call).
->(value) { value * 2 }
^^^^^^^^^^^^^^^^^^^^^^^
Public Class Methods
(Source source, Integer node_id, Location location, Integer flags, Array[Symbol] locals, Location operator_loc, Location opening_loc, Location closing_loc, (BlockParametersNode | NumberedParametersNode | ItParametersNode)? parameters, (StatementsNode | BeginNode)? body) → void
Source
# File lib/prism/node.rb, line 19690 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
Initialize a new LambdaNode node.
Public Instance Methods
Source
# File lib/prism/node.rb, line 19886 def body @body end
Returns the body attribute.
Source
# File lib/prism/node.rb, line 19800 def locals @locals end
Returns the locals attribute.
Source
# File lib/prism/node.rb, line 19876 def parameters @parameters end
Returns the parameters attribute.
Locations
Public Instance Methods
() → Location
Source
# File lib/prism/node.rb, line 19855 def closing_loc location = @closing_loc return location if location.is_a?(Location) @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
Returns the Location represented by closing_loc.
() → Location
Source
# File lib/prism/node.rb, line 19833 def opening_loc location = @opening_loc return location if location.is_a?(Location) @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
Returns the Location represented by opening_loc.
() → Location
Source
# File lib/prism/node.rb, line 19811 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
Returns the Location represented by operator_loc.
Node Interface
These methods are present on all subclasses of Node. Read the node interface docs for more information.
Public Class Methods
Public Instance Methods
(_Visitor visitor) → untyped
Source
# File lib/prism/node.rb, line 19717 def accept(visitor) visitor.visit_lambda_node(self) end
See Node.accept.
() → Array[node?]
Source
# File lib/prism/node.rb, line 19724 def child_nodes [parameters, body] end
See Node.child_nodes.
() → Array[node | Location]
Source
# File lib/prism/node.rb, line 19752 def comment_targets [operator_loc, opening_loc, closing_loc, *parameters, *body] #: Array[Prism::node | Location] end
See Node.comment_targets.
() → Array[node]
Source
# File lib/prism/node.rb, line 19742 def compact_child_nodes compact = [] #: Array[Prism::node] if (parameters = self.parameters); compact << parameters; end if (body = self.body); compact << body; end compact end
(?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array[Symbol], ?operator_loc: Location, ?opening_loc: Location, ?closing_loc: Location, ?parameters: (BlockParametersNode | NumberedParametersNode | ItParametersNode)?, ?body: (StatementsNode | BeginNode)?) → LambdaNode
Source
# File lib/prism/node.rb, line 19762 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
Creates a copy of self with the given fields, using self as the template.
() → Enumerator[node, void]
() { (node) → void } → void
Source
# File lib/prism/node.rb, line 19732 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? if (parameters = self.parameters); yield parameters; end if (body = self.body); yield body; end end
See Node.each_child_node.
Repository
Methods related to Relocation.
Public Instance Methods
(_Repository repository) → Relocation::Entry
Source
# File lib/prism/node.rb, line 19866 def save_closing_loc(repository) repository.enter(node_id, :closing_loc) end
Save the closing_loc location using the given saved source so that it can be retrieved later.
(_Repository repository) → Relocation::Entry
Source
# File lib/prism/node.rb, line 19844 def save_opening_loc(repository) repository.enter(node_id, :opening_loc) end
Save the opening_loc location using the given saved source so that it can be retrieved later.
(_Repository repository) → Relocation::Entry
Source
# File lib/prism/node.rb, line 19822 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end
Save the operator_loc location using the given saved source so that it can be retrieved later.
Slicing
Public Instance Methods
() → String
Source
# File lib/prism/node.rb, line 19918 def closing closing_loc.slice end
Slice the location of closing_loc from the source.
() → String
Source
# File lib/prism/node.rb, line 19908 def opening opening_loc.slice end
Slice the location of opening_loc from the source.
() → String
Source
# File lib/prism/node.rb, line 19898 def operator operator_loc.slice end
Slice the location of operator_loc from the source.