Class: Prism::BlockNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::BlockNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a block of ruby code.
[1, 2, 3].each { |i| puts x }
^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
attr_reader body: StatementsNode | BeginNode | nil.
-
#locals ⇒ Object
readonly
attr_reader locals: Array.
-
#parameters ⇒ Object
readonly
attr_reader parameters: BlockParametersNode | NumberedParametersNode | ItParametersNode | nil.
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].
-
#closing ⇒ Object
def closing: () -> String.
-
#closing_loc ⇒ Object
attr_reader closing_loc: Location.
-
#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, locals: self.locals, parameters: self.parameters, body: self.body, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?parameters: BlockParametersNode | NumberedParametersNode | ItParametersNode | nil, ?body: StatementsNode | BeginNode | nil, ?opening_loc: Location, ?closing_loc: Location) -> BlockNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(source, node_id, location, flags, locals, parameters, body, opening_loc, closing_loc) ⇒ BlockNode
constructor
Initialize a new BlockNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#opening ⇒ Object
def opening: () -> String.
-
#opening_loc ⇒ Object
attr_reader opening_loc: Location.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, locals, parameters, body, opening_loc, closing_loc) ⇒ BlockNode
Initialize a new BlockNode node.
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 |
# File 'lib/prism/node.rb', line 1579 def initialize(source, node_id, location, flags, locals, parameters, body, opening_loc, closing_loc) @source = source @node_id = node_id @location = location @flags = flags @locals = locals @parameters = parameters @body = body @opening_loc = opening_loc @closing_loc = closing_loc end |
Instance Attribute Details
#body ⇒ Object (readonly)
attr_reader body: StatementsNode | BeginNode | nil
1634 1635 1636 |
# File 'lib/prism/node.rb', line 1634 def body @body end |
#locals ⇒ Object (readonly)
attr_reader locals: Array
1628 1629 1630 |
# File 'lib/prism/node.rb', line 1628 def locals @locals end |
#parameters ⇒ Object (readonly)
attr_reader parameters: BlockParametersNode | NumberedParametersNode | ItParametersNode | nil
1631 1632 1633 |
# File 'lib/prism/node.rb', line 1631 def parameters @parameters end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
1671 1672 1673 |
# File 'lib/prism/node.rb', line 1671 def self.type :block_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.
1677 1678 1679 1680 1681 1682 1683 1684 1685 |
# File 'lib/prism/node.rb', line 1677 def ===(other) other.is_a?(BlockNode) && (locals.length == other.locals.length) && locals.zip(other.locals).all? { |left, right| left === right } && (parameters === other.parameters) && (body === other.body) && (opening_loc.nil? == other.opening_loc.nil?) && (closing_loc.nil? == other.closing_loc.nil?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
1592 1593 1594 |
# File 'lib/prism/node.rb', line 1592 def accept(visitor) visitor.visit_block_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
1597 1598 1599 |
# File 'lib/prism/node.rb', line 1597 def child_nodes [parameters, body] end |
#closing ⇒ Object
def closing: () -> String
1656 1657 1658 |
# File 'lib/prism/node.rb', line 1656 def closing closing_loc.slice end |
#closing_loc ⇒ Object
attr_reader closing_loc: Location
1644 1645 1646 1647 1648 |
# File 'lib/prism/node.rb', line 1644 def closing_loc location = @closing_loc return location if location.is_a?(Location) @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
1610 1611 1612 |
# File 'lib/prism/node.rb', line 1610 def comment_targets [*parameters, *body, opening_loc, closing_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
1602 1603 1604 1605 1606 1607 |
# File 'lib/prism/node.rb', line 1602 def compact_child_nodes compact = [] #: Array[Prism::node] compact << parameters if parameters compact << body if body compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, parameters: self.parameters, body: self.body, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?parameters: BlockParametersNode | NumberedParametersNode | ItParametersNode | nil, ?body: StatementsNode | BeginNode | nil, ?opening_loc: Location, ?closing_loc: Location) -> BlockNode
1615 1616 1617 |
# File 'lib/prism/node.rb', line 1615 def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, parameters: self.parameters, body: self.body, opening_loc: self.opening_loc, closing_loc: self.closing_loc) BlockNode.new(source, node_id, location, flags, locals, parameters, body, opening_loc, closing_loc) end |
#deconstruct_keys(keys) ⇒ Object
1623 1624 1625 |
# File 'lib/prism/node.rb', line 1623 def deconstruct_keys(keys) { node_id: node_id, location: location, locals: locals, parameters: parameters, body: body, opening_loc: opening_loc, closing_loc: closing_loc } end |
#inspect ⇒ Object
def inspect -> String
1661 1662 1663 |
# File 'lib/prism/node.rb', line 1661 def inspect InspectVisitor.compose(self) end |
#opening ⇒ Object
def opening: () -> String
1651 1652 1653 |
# File 'lib/prism/node.rb', line 1651 def opening opening_loc.slice end |
#opening_loc ⇒ Object
attr_reader opening_loc: Location
1637 1638 1639 1640 1641 |
# File 'lib/prism/node.rb', line 1637 def opening_loc location = @opening_loc return location if location.is_a?(Location) @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
1666 1667 1668 |
# File 'lib/prism/node.rb', line 1666 def type :block_node end |