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.
1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 |
# File 'lib/prism/node.rb', line 1844 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
1895 1896 1897 |
# File 'lib/prism/node.rb', line 1895 def locals @locals end |
#parameters ⇒ Object (readonly)
attr_reader parameters: ParametersNode?
1892 1893 1894 |
# File 'lib/prism/node.rb', line 1892 def parameters @parameters end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
1944 1945 1946 |
# File 'lib/prism/node.rb', line 1944 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.
1950 1951 1952 1953 1954 1955 1956 1957 |
# File 'lib/prism/node.rb', line 1950 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
1856 1857 1858 |
# File 'lib/prism/node.rb', line 1856 def accept(visitor) visitor.visit_block_parameters_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
1861 1862 1863 |
# File 'lib/prism/node.rb', line 1861 def child_nodes [parameters, *locals] end |
#closing ⇒ Object
def closing: () -> String?
1929 1930 1931 |
# File 'lib/prism/node.rb', line 1929 def closing closing_loc&.slice end |
#closing_loc ⇒ Object
attr_reader closing_loc: Location?
1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 |
# File 'lib/prism/node.rb', line 1911 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]
1874 1875 1876 |
# File 'lib/prism/node.rb', line 1874 def comment_targets [*parameters, *locals, *opening_loc, *closing_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
1866 1867 1868 1869 1870 1871 |
# File 'lib/prism/node.rb', line 1866 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
1879 1880 1881 |
# File 'lib/prism/node.rb', line 1879 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
1887 1888 1889 |
# File 'lib/prism/node.rb', line 1887 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
1934 1935 1936 |
# File 'lib/prism/node.rb', line 1934 def inspect InspectVisitor.compose(self) end |
#opening ⇒ Object
def opening: () -> String?
1924 1925 1926 |
# File 'lib/prism/node.rb', line 1924 def opening opening_loc&.slice end |
#opening_loc ⇒ Object
attr_reader opening_loc: Location?
1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 |
# File 'lib/prism/node.rb', line 1898 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`.
1939 1940 1941 |
# File 'lib/prism/node.rb', line 1939 def type :block_parameters_node end |