Class: Prism::BlockParameterNode

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

Overview

Represents a block parameter of a method, block, or lambda definition.

def a(&b)
      ^^
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, name, name_loc, operator_loc) ⇒ BlockParameterNode

Initialize a new BlockParameterNode node.



1732
1733
1734
1735
1736
1737
1738
1739
1740
# File 'lib/prism/node.rb', line 1732

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

Instance Attribute Details

#nameObject (readonly)

attr_reader name: Symbol?



1781
1782
1783
# File 'lib/prism/node.rb', line 1781

def name
  @name
end

Class Method Details

.typeObject

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



1819
1820
1821
# File 'lib/prism/node.rb', line 1819

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



1825
1826
1827
1828
1829
1830
1831
# File 'lib/prism/node.rb', line 1825

def ===(other)
  other.is_a?(BlockParameterNode) &&
    (flags === other.flags) &&
    (name === other.name) &&
    (name_loc.nil? == other.name_loc.nil?) &&
    (operator_loc.nil? == other.operator_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



1743
1744
1745
# File 'lib/prism/node.rb', line 1743

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

#child_nodesObject Also known as: deconstruct

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



1748
1749
1750
# File 'lib/prism/node.rb', line 1748

def child_nodes
  []
end

#comment_targetsObject

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



1758
1759
1760
# File 'lib/prism/node.rb', line 1758

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



1753
1754
1755
# File 'lib/prism/node.rb', line 1753

def compact_child_nodes
  []
end

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

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?name: Symbol?, ?name_loc: Location?, ?operator_loc: Location) -> BlockParameterNode



1763
1764
1765
# File 'lib/prism/node.rb', line 1763

def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, name_loc: self.name_loc, operator_loc: self.operator_loc)
  BlockParameterNode.new(source, node_id, location, flags, name, name_loc, operator_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, name: Symbol?, name_loc: Location?, operator_loc: Location }



1771
1772
1773
# File 'lib/prism/node.rb', line 1771

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

#inspectObject

def inspect -> String



1809
1810
1811
# File 'lib/prism/node.rb', line 1809

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

attr_reader name_loc: Location?



1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
# File 'lib/prism/node.rb', line 1784

def name_loc
  location = @name_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @name_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end

#operatorObject

def operator: () -> String



1804
1805
1806
# File 'lib/prism/node.rb', line 1804

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



1797
1798
1799
1800
1801
# File 'lib/prism/node.rb', line 1797

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

#repeated_parameter?Boolean

def repeated_parameter?: () -> bool

Returns:

  • (Boolean)


1776
1777
1778
# File 'lib/prism/node.rb', line 1776

def repeated_parameter?
  flags.anybits?(ParameterFlags::REPEATED_PARAMETER)
end

#typeObject

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



1814
1815
1816
# File 'lib/prism/node.rb', line 1814

def type
  :block_parameter_node
end