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.



2113
2114
2115
2116
2117
2118
2119
2120
2121
# File 'lib/prism/node.rb', line 2113

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)

The name of the block parameter.

def a(&b) # name `:b`
       ^
end


2172
2173
2174
# File 'lib/prism/node.rb', line 2172

def name
  @name
end

Class Method Details

.typeObject

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



2229
2230
2231
# File 'lib/prism/node.rb', line 2229

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.



2235
2236
2237
2238
2239
2240
2241
# File 'lib/prism/node.rb', line 2235

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



2124
2125
2126
# File 'lib/prism/node.rb', line 2124

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



2129
2130
2131
# File 'lib/prism/node.rb', line 2129

def child_nodes
  []
end

#comment_targetsObject

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



2145
2146
2147
# File 'lib/prism/node.rb', line 2145

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



2140
2141
2142
# File 'lib/prism/node.rb', line 2140

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



2150
2151
2152
# File 'lib/prism/node.rb', line 2150

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 }



2158
2159
2160
# File 'lib/prism/node.rb', line 2158

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

#each_child_nodeObject

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator



2134
2135
2136
2137
# File 'lib/prism/node.rb', line 2134

def each_child_node
  return to_enum(:each_child_node) unless block_given?

end

#inspectObject

def inspect -> String



2219
2220
2221
# File 'lib/prism/node.rb', line 2219

def inspect
  InspectVisitor.compose(self)
end

#name_locObject

Represents the location of the block parameter name.

def a(&b)
       ^


2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
# File 'lib/prism/node.rb', line 2178

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



2214
2215
2216
# File 'lib/prism/node.rb', line 2214

def operator
  operator_loc.slice
end

#operator_locObject

Represents the location of the ‘&` operator.

def a(&b)
      ^
end


2201
2202
2203
2204
2205
# File 'lib/prism/node.rb', line 2201

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)


2163
2164
2165
# File 'lib/prism/node.rb', line 2163

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

#save_name_loc(repository) ⇒ Object

Save the name_loc location using the given saved source so that it can be retrieved later.



2192
2193
2194
# File 'lib/prism/node.rb', line 2192

def save_name_loc(repository)
  repository.enter(node_id, :name_loc) unless @name_loc.nil?
end

#save_operator_loc(repository) ⇒ Object

Save the operator_loc location using the given saved source so that it can be retrieved later.



2209
2210
2211
# File 'lib/prism/node.rb', line 2209

def save_operator_loc(repository)
  repository.enter(node_id, :operator_loc)
end

#typeObject

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



2224
2225
2226
# File 'lib/prism/node.rb', line 2224

def type
  :block_parameter_node
end