Class: Prism::BlockParametersNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::BlockParametersNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a block’s parameters declaration.
-> (a, b = 1; local) { }
^^^^^^^^^^^^^^^^^
foo do |a, b = 1; local|
^^^^^^^^^^^^^^^^^
end
Instance Attribute Summary collapse
-
#locals ⇒ Object
readonly
attr_reader locals: Array.
-
#parameters ⇒ Object
readonly
attr_reader parameters: ParametersNode?.
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, parameters: self.parameters, locals: self.locals, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?parameters: ParametersNode?, ?locals: Array, ?opening_loc: Location?, ?closing_loc: Location?) -> BlockParametersNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(source, node_id, location, flags, parameters, locals, opening_loc, closing_loc) ⇒ BlockParametersNode
constructor
Initialize a new BlockParametersNode 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, parameters, locals, opening_loc, closing_loc) ⇒ BlockParametersNode
Initialize a new BlockParametersNode node.
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 |
# File 'lib/prism/node.rb', line 1807 def initialize(source, node_id, location, flags, parameters, locals, opening_loc, closing_loc) @source = source @node_id = node_id @location = location @flags = flags @parameters = parameters @locals = locals @opening_loc = opening_loc @closing_loc = closing_loc end |
Instance Attribute Details
#locals ⇒ Object (readonly)
attr_reader locals: Array
1858 1859 1860 |
# File 'lib/prism/node.rb', line 1858 def locals @locals end |
#parameters ⇒ Object (readonly)
attr_reader parameters: ParametersNode?
1855 1856 1857 |
# File 'lib/prism/node.rb', line 1855 def parameters @parameters end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
1907 1908 1909 |
# File 'lib/prism/node.rb', line 1907 def self.type :block_parameters_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.
1913 1914 1915 1916 1917 1918 1919 1920 |
# File 'lib/prism/node.rb', line 1913 def ===(other) other.is_a?(BlockParametersNode) && (parameters === other.parameters) && (locals.length == other.locals.length) && locals.zip(other.locals).all? { |left, right| left === right } && (opening_loc.nil? == other.opening_loc.nil?) && (closing_loc.nil? == other.closing_loc.nil?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
1819 1820 1821 |
# File 'lib/prism/node.rb', line 1819 def accept(visitor) visitor.visit_block_parameters_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
1824 1825 1826 |
# File 'lib/prism/node.rb', line 1824 def child_nodes [parameters, *locals] end |
#closing ⇒ Object
def closing: () -> String?
1892 1893 1894 |
# File 'lib/prism/node.rb', line 1892 def closing closing_loc&.slice end |
#closing_loc ⇒ Object
attr_reader closing_loc: Location?
1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 |
# File 'lib/prism/node.rb', line 1874 def closing_loc location = @closing_loc case location when nil nil when Location location else @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
1837 1838 1839 |
# File 'lib/prism/node.rb', line 1837 def comment_targets [*parameters, *locals, *opening_loc, *closing_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
1829 1830 1831 1832 1833 1834 |
# File 'lib/prism/node.rb', line 1829 def compact_child_nodes compact = [] #: Array[Prism::node] compact << parameters if parameters compact.concat(locals) compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, parameters: self.parameters, locals: self.locals, opening_loc: self.opening_loc, closing_loc: self.closing_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?parameters: ParametersNode?, ?locals: Array, ?opening_loc: Location?, ?closing_loc: Location?) -> BlockParametersNode
1842 1843 1844 |
# File 'lib/prism/node.rb', line 1842 def copy(node_id: self.node_id, location: self.location, flags: self.flags, parameters: self.parameters, locals: self.locals, opening_loc: self.opening_loc, closing_loc: self.closing_loc) BlockParametersNode.new(source, node_id, location, flags, parameters, locals, opening_loc, closing_loc) end |
#deconstruct_keys(keys) ⇒ Object
1850 1851 1852 |
# File 'lib/prism/node.rb', line 1850 def deconstruct_keys(keys) { node_id: node_id, location: location, parameters: parameters, locals: locals, opening_loc: opening_loc, closing_loc: closing_loc } end |
#inspect ⇒ Object
def inspect -> String
1897 1898 1899 |
# File 'lib/prism/node.rb', line 1897 def inspect InspectVisitor.compose(self) end |
#opening ⇒ Object
def opening: () -> String?
1887 1888 1889 |
# File 'lib/prism/node.rb', line 1887 def opening opening_loc&.slice end |
#opening_loc ⇒ Object
attr_reader opening_loc: Location?
1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 |
# File 'lib/prism/node.rb', line 1861 def opening_loc location = @opening_loc case location when nil nil when Location location else @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
1902 1903 1904 |
# File 'lib/prism/node.rb', line 1902 def type :block_parameters_node end |