Class: Prism::BlockArgumentNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::BlockArgumentNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a block argument using ‘&`.
bar(&args)
^^^^^^^^^^
Instance Attribute Summary collapse
-
#expression ⇒ Object
readonly
The expression that is being passed as a block argument.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#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.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, expression: Prism::node?, operator_loc: Location }.
-
#initialize(source, node_id, location, flags, expression, operator_loc) ⇒ BlockArgumentNode
constructor
Initialize a new BlockArgumentNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#operator ⇒ Object
def operator: () -> String.
-
#operator_loc ⇒ Object
Represents the location of the ‘&` operator.
-
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, expression, operator_loc) ⇒ BlockArgumentNode
Initialize a new BlockArgumentNode node.
1648 1649 1650 1651 1652 1653 1654 1655 |
# File 'lib/prism/node.rb', line 1648 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
#expression ⇒ Object (readonly)
The expression that is being passed as a block argument. This can be any [non-void expression](github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
foo(&args)
^^^^^
1696 1697 1698 |
# File 'lib/prism/node.rb', line 1696 def expression @expression end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
1730 1731 1732 |
# File 'lib/prism/node.rb', line 1730 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.
1736 1737 1738 1739 1740 |
# File 'lib/prism/node.rb', line 1736 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
1658 1659 1660 |
# File 'lib/prism/node.rb', line 1658 def accept(visitor) visitor.visit_block_argument_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
1663 1664 1665 |
# File 'lib/prism/node.rb', line 1663 def child_nodes [expression] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
1675 1676 1677 |
# File 'lib/prism/node.rb', line 1675 def comment_targets [*expression, operator_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
1668 1669 1670 1671 1672 |
# File 'lib/prism/node.rb', line 1668 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
1680 1681 1682 |
# File 'lib/prism/node.rb', line 1680 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 }
1688 1689 1690 |
# File 'lib/prism/node.rb', line 1688 def deconstruct_keys(keys) { node_id: node_id, location: location, expression: expression, operator_loc: operator_loc } end |
#inspect ⇒ Object
def inspect -> String
1720 1721 1722 |
# File 'lib/prism/node.rb', line 1720 def inspect InspectVisitor.compose(self) end |
#operator ⇒ Object
def operator: () -> String
1715 1716 1717 |
# File 'lib/prism/node.rb', line 1715 def operator operator_loc.slice end |
#operator_loc ⇒ Object
Represents the location of the ‘&` operator.
foo(&args)
^
1702 1703 1704 1705 1706 |
# File 'lib/prism/node.rb', line 1702 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
1710 1711 1712 |
# File 'lib/prism/node.rb', line 1710 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
1725 1726 1727 |
# File 'lib/prism/node.rb', line 1725 def type :block_argument_node end |