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.



1448
1449
1450
1451
1452
1453
1454
1455
# File 'lib/prism/node.rb', line 1448

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?



1493
1494
1495
# File 'lib/prism/node.rb', line 1493

def expression
  @expression
end

Class Method Details

.typeObject

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



1518
1519
1520
# File 'lib/prism/node.rb', line 1518

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.



1524
1525
1526
1527
1528
# File 'lib/prism/node.rb', line 1524

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



1458
1459
1460
# File 'lib/prism/node.rb', line 1458

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

#child_nodesObject Also known as: deconstruct

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



1463
1464
1465
# File 'lib/prism/node.rb', line 1463

def child_nodes
  [expression]
end

#comment_targetsObject

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



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

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



1468
1469
1470
1471
1472
# File 'lib/prism/node.rb', line 1468

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



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

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 }



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

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

#inspectObject

def inspect -> String



1508
1509
1510
# File 'lib/prism/node.rb', line 1508

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



1503
1504
1505
# File 'lib/prism/node.rb', line 1503

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



1496
1497
1498
1499
1500
# File 'lib/prism/node.rb', line 1496

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`.



1513
1514
1515
# File 'lib/prism/node.rb', line 1513

def type
  :block_argument_node
end