class YARP::LambdaNode

Represents using a lambda literal (not the lambda method call).

->(value) { value * 2 }
^^^^^^^^^^^^^^^^^^^^^^^

Attributes

body[R]

attr_reader body: Node?

closing_loc[R]

attr_reader closing_loc: Location

locals[R]

attr_reader locals: Array

opening_loc[R]

attr_reader opening_loc: Location

operator_loc[R]

attr_reader operator_loc: Location

parameters[R]

attr_reader parameters: BlockParametersNode?

Public Class Methods

new(locals, operator_loc, opening_loc, closing_loc, parameters, body, location) click to toggle source

def initialize: (locals: Array, operator_loc: Location, opening_loc: Location, closing_loc: Location, parameters: BlockParametersNode?, body: Node?, location: Location) -> void

# File yarp/node.rb, line 6599
def initialize(locals, operator_loc, opening_loc, closing_loc, parameters, body, location)
  @locals = locals
  @operator_loc = operator_loc
  @opening_loc = opening_loc
  @closing_loc = closing_loc
  @parameters = parameters
  @body = body
  @location = location
end

Public Instance Methods

accept(visitor) click to toggle source

def accept: (visitor: Visitor) -> void

# File yarp/node.rb, line 6610
def accept(visitor)
  visitor.visit_lambda_node(self)
end
child_nodes() click to toggle source

def child_nodes: () -> Array[nil | Node]

# File yarp/node.rb, line 6615
def child_nodes
  [parameters, body]
end
Also aliased as: deconstruct
closing() click to toggle source

def closing: () -> String

# File yarp/node.rb, line 6656
def closing
  closing_loc.slice
end
comment_targets() click to toggle source

def comment_targets: () -> Array[Node | Location]

# File yarp/node.rb, line 6620
def comment_targets
  [operator_loc, opening_loc, closing_loc, *parameters, *body]
end
copy(**params) click to toggle source

def copy: (**params) -> LambdaNode

# File yarp/node.rb, line 6625
def copy(**params)
  LambdaNode.new(
    params.fetch(:locals) { locals },
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:opening_loc) { opening_loc },
    params.fetch(:closing_loc) { closing_loc },
    params.fetch(:parameters) { parameters },
    params.fetch(:body) { body },
    params.fetch(:location) { location },
  )
end
deconstruct()

def deconstruct: () -> Array[nil | Node]

Alias for: child_nodes
deconstruct_keys(keys) click to toggle source

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]

# File yarp/node.rb, line 6641
def deconstruct_keys(keys)
  { locals: locals, operator_loc: operator_loc, opening_loc: opening_loc, closing_loc: closing_loc, parameters: parameters, body: body, location: location }
end
inspect(inspector = NodeInspector.new) click to toggle source
# File yarp/node.rb, line 6660
def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── locals: #{locals.inspect}\n"
  inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n"
  inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n"
  inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n"
  if (parameters = self.parameters).nil?
    inspector << "├── parameters: ∅\n"
  else
    inspector << "├── parameters:\n"
    inspector << parameters.inspect(inspector.child_inspector("│   ")).delete_prefix(inspector.prefix)
  end
  if (body = self.body).nil?
    inspector << "└── body: ∅\n"
  else
    inspector << "└── body:\n"
    inspector << body.inspect(inspector.child_inspector("    ")).delete_prefix(inspector.prefix)
  end
  inspector.to_str
end
opening() click to toggle source

def opening: () -> String

# File yarp/node.rb, line 6651
def opening
  opening_loc.slice
end
operator() click to toggle source

def operator: () -> String

# File yarp/node.rb, line 6646
def operator
  operator_loc.slice
end