Class: Prism::BlockArgumentNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
ext/prism/api_node.c

Overview

Represents a block argument using ‘&`.

bar(&args)
^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, expression, operator_loc) ⇒ BlockArgumentNode

Initialize a new BlockArgumentNode node.



1411
1412
1413
1414
1415
1416
1417
1418
# File 'lib/prism/node.rb', line 1411

def initialize(source, node_id, location, flags, expression, operator_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @expression = expression
  @operator_loc = operator_loc
end

Instance Attribute Details

#expressionObject (readonly)

attr_reader expression: Prism::node?



1456
1457
1458
# File 'lib/prism/node.rb', line 1456

def expression
  @expression
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



1481
1482
1483
# File 'lib/prism/node.rb', line 1481

def self.type
  :block_argument_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.



1487
1488
1489
1490
1491
# File 'lib/prism/node.rb', line 1487

def ===(other)
  other.is_a?(BlockArgumentNode) &&
    (expression === other.expression) &&
    (operator_loc.nil? == other.operator_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



1421
1422
1423
# File 'lib/prism/node.rb', line 1421

def accept(visitor)
  visitor.visit_block_argument_node(self)
end

#child_nodesObject Also known as: deconstruct

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



1426
1427
1428
# File 'lib/prism/node.rb', line 1426

def child_nodes
  [expression]
end

#comment_targetsObject

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



1438
1439
1440
# File 'lib/prism/node.rb', line 1438

def comment_targets
  [*expression, operator_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



1431
1432
1433
1434
1435
# File 'lib/prism/node.rb', line 1431

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << expression if expression
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, expression: self.expression, operator_loc: self.operator_loc) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?expression: Prism::node?, ?operator_loc: Location) -> BlockArgumentNode



1443
1444
1445
# File 'lib/prism/node.rb', line 1443

def copy(node_id: self.node_id, location: self.location, flags: self.flags, expression: self.expression, operator_loc: self.operator_loc)
  BlockArgumentNode.new(source, node_id, location, flags, expression, operator_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, expression: Prism::node?, operator_loc: Location }



1451
1452
1453
# File 'lib/prism/node.rb', line 1451

def deconstruct_keys(keys)
  { node_id: node_id, location: location, expression: expression, operator_loc: operator_loc }
end

#inspectObject

def inspect -> String



1471
1472
1473
# File 'lib/prism/node.rb', line 1471

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



1466
1467
1468
# File 'lib/prism/node.rb', line 1466

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



1459
1460
1461
1462
1463
# File 'lib/prism/node.rb', line 1459

def operator_loc
  location = @operator_loc
  return location if location.is_a?(Location)
  @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



1476
1477
1478
# File 'lib/prism/node.rb', line 1476

def type
  :block_argument_node
end