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
Represents the local variables of the block.
-
#parameters ⇒ Object
readonly
Represents the parameters of the block.
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.
-
#closing ⇒ Object
def closing: () -> String?.
-
#closing_loc ⇒ Object
Represents the closing location of the block parameters.
-
#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
Represents the opening location of the block parameters.
-
#save_closing_loc(repository) ⇒ Object
Save the closing_loc location using the given saved source so that it can be retrieved later.
-
#save_opening_loc(repository) ⇒ Object
Save the opening_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, parameters, locals, opening_loc, closing_loc) ⇒ BlockParametersNode
Initialize a new BlockParametersNode node.
2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 |
# File 'lib/prism/node.rb', line 2125 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)
Represents the local variables of the block.
-> (a, b = 1; local) { }
^^^^^
foo do |a, b = 1; local|
^^^^^
end
2190 2191 2192 |
# File 'lib/prism/node.rb', line 2190 def locals @locals end |
#parameters ⇒ Object (readonly)
Represents the parameters of the block.
-> (a, b = 1; local) { }
^^^^^^^^
foo do |a, b = 1; local|
^^^^^^^^
end
2180 2181 2182 |
# File 'lib/prism/node.rb', line 2180 def parameters @parameters end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
2265 2266 2267 |
# File 'lib/prism/node.rb', line 2265 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.
2271 2272 2273 2274 2275 2276 2277 2278 |
# File 'lib/prism/node.rb', line 2271 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
2137 2138 2139 |
# File 'lib/prism/node.rb', line 2137 def accept(visitor) visitor.visit_block_parameters_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
2142 2143 2144 |
# File 'lib/prism/node.rb', line 2142 def child_nodes [parameters, *locals] end |
#closing ⇒ Object
def closing: () -> String?
2250 2251 2252 |
# File 'lib/prism/node.rb', line 2250 def closing closing_loc&.slice end |
#closing_loc ⇒ Object
Represents the closing location of the block parameters.
-> (a, b = 1; local) { }
^
foo do |a, b = 1; local|
^
end
2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 |
# File 'lib/prism/node.rb', line 2226 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]
2155 2156 2157 |
# File 'lib/prism/node.rb', line 2155 def comment_targets [*parameters, *locals, *opening_loc, *closing_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
2147 2148 2149 2150 2151 2152 |
# File 'lib/prism/node.rb', line 2147 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
2160 2161 2162 |
# File 'lib/prism/node.rb', line 2160 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
2168 2169 2170 |
# File 'lib/prism/node.rb', line 2168 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
2255 2256 2257 |
# File 'lib/prism/node.rb', line 2255 def inspect InspectVisitor.compose(self) end |
#opening ⇒ Object
def opening: () -> String?
2245 2246 2247 |
# File 'lib/prism/node.rb', line 2245 def opening opening_loc&.slice end |
#opening_loc ⇒ Object
Represents the opening location of the block parameters.
-> (a, b = 1; local) { }
^
foo do |a, b = 1; local|
^
end
2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 |
# File 'lib/prism/node.rb', line 2200 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 |
#save_closing_loc(repository) ⇒ Object
Save the closing_loc location using the given saved source so that it can be retrieved later.
2240 2241 2242 |
# File 'lib/prism/node.rb', line 2240 def save_closing_loc(repository) repository.enter(node_id, :closing_loc) unless @closing_loc.nil? end |
#save_opening_loc(repository) ⇒ Object
Save the opening_loc location using the given saved source so that it can be retrieved later.
2214 2215 2216 |
# File 'lib/prism/node.rb', line 2214 def save_opening_loc(repository) repository.enter(node_id, :opening_loc) unless @opening_loc.nil? end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
2260 2261 2262 |
# File 'lib/prism/node.rb', line 2260 def type :block_parameters_node end |