class Ruby::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/ruby/prism/node.rb, line 21118 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/ruby/prism/node.rb, line 21323 def body @body end
Returns the body attribute.
Source
# File lib/ruby/prism/node.rb, line 21237 def locals @locals end
Returns the locals attribute.
Source
# File lib/ruby/prism/node.rb, line 21313 def parameters @parameters end
Returns the parameters attribute.
Locations
Public Instance Methods
() → Location
Source
# File lib/ruby/prism/node.rb, line 21292 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/ruby/prism/node.rb, line 21270 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/ruby/prism/node.rb, line 21248 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/ruby/prism/node.rb, line 21145 def accept(visitor) visitor.visit_lambda_node(self) end
See Node.accept.
() → Array[node?]
Source
# File lib/ruby/prism/node.rb, line 21152 def child_nodes [parameters, body] end
See Node.child_nodes.
() → Array[node]
Source
# File lib/ruby/prism/node.rb, line 21170 def compact_child_nodes compact = [] #: Array[Ruby::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/ruby/prism/node.rb, line 21183 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/ruby/prism/node.rb, line 21160 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/ruby/prism/node.rb, line 21303 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/ruby/prism/node.rb, line 21281 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/ruby/prism/node.rb, line 21259 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/ruby/prism/node.rb, line 21355 def closing closing_loc.slice end
Slice the location of closing_loc from the source.
() → String
Source
# File lib/ruby/prism/node.rb, line 21345 def opening opening_loc.slice end
Slice the location of opening_loc from the source.
() → String
Source
# File lib/ruby/prism/node.rb, line 21335 def operator operator_loc.slice end
Slice the location of operator_loc from the source.