Class: YARP::LambdaNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::LambdaNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/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: Node?.
-
#closing_loc ⇒ Object
readonly
attr_reader closing_loc: Location.
-
#locals ⇒ Object
readonly
attr_reader locals: Array.
-
#opening_loc ⇒ Object
readonly
attr_reader opening_loc: Location.
-
#operator_loc ⇒ Object
readonly
attr_reader operator_loc: Location.
-
#parameters ⇒ Object
readonly
attr_reader parameters: BlockParametersNode?.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#closing ⇒ Object
def closing: () -> String.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#copy(**params) ⇒ Object
def copy: (**params) -> LambdaNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(locals, operator_loc, opening_loc, closing_loc, parameters, body, location) ⇒ LambdaNode
constructor
def initialize: (locals: Array, operator_loc: Location, opening_loc: Location, closing_loc: Location, parameters: BlockParametersNode?, body: Node?, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#opening ⇒ Object
def opening: () -> String.
-
#operator ⇒ Object
def operator: () -> String.
Constructor Details
#initialize(locals, operator_loc, opening_loc, closing_loc, parameters, body, location) ⇒ LambdaNode
def initialize: (locals: Array, operator_loc: Location, opening_loc: Location, closing_loc: Location, parameters: BlockParametersNode?, body: Node?, location: Location) -> void
6367 6368 6369 6370 6371 6372 6373 6374 6375 |
# File 'lib/yarp/node.rb', line 6367 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 |
Instance Attribute Details
#body ⇒ Object (readonly)
attr_reader body: Node?
6364 6365 6366 |
# File 'lib/yarp/node.rb', line 6364 def body @body end |
#closing_loc ⇒ Object (readonly)
attr_reader closing_loc: Location
6358 6359 6360 |
# File 'lib/yarp/node.rb', line 6358 def closing_loc @closing_loc end |
#locals ⇒ Object (readonly)
attr_reader locals: Array
6349 6350 6351 |
# File 'lib/yarp/node.rb', line 6349 def locals @locals end |
#opening_loc ⇒ Object (readonly)
attr_reader opening_loc: Location
6355 6356 6357 |
# File 'lib/yarp/node.rb', line 6355 def opening_loc @opening_loc end |
#operator_loc ⇒ Object (readonly)
attr_reader operator_loc: Location
6352 6353 6354 |
# File 'lib/yarp/node.rb', line 6352 def operator_loc @operator_loc end |
#parameters ⇒ Object (readonly)
attr_reader parameters: BlockParametersNode?
6361 6362 6363 |
# File 'lib/yarp/node.rb', line 6361 def parameters @parameters end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
6378 6379 6380 |
# File 'lib/yarp/node.rb', line 6378 def accept(visitor) visitor.visit_lambda_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
6383 6384 6385 |
# File 'lib/yarp/node.rb', line 6383 def child_nodes [parameters, body] end |
#closing ⇒ Object
def closing: () -> String
6424 6425 6426 |
# File 'lib/yarp/node.rb', line 6424 def closing closing_loc.slice end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
6388 6389 6390 |
# File 'lib/yarp/node.rb', line 6388 def comment_targets [operator_loc, opening_loc, closing_loc, *parameters, *body] end |
#copy(**params) ⇒ Object
def copy: (**params) -> LambdaNode
6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 |
# File 'lib/yarp/node.rb', line 6393 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_keys(keys) ⇒ Object
6409 6410 6411 |
# File 'lib/yarp/node.rb', line 6409 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) ⇒ Object
6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 |
# File 'lib/yarp/node.rb', line 6428 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 ⇒ Object
def opening: () -> String
6419 6420 6421 |
# File 'lib/yarp/node.rb', line 6419 def opening opening_loc.slice end |
#operator ⇒ Object
def operator: () -> String
6414 6415 6416 |
# File 'lib/yarp/node.rb', line 6414 def operator operator_loc.slice end |