Class: Prism::AssocSplatNode

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

Overview

Represents a splat in a hash literal.

{ **foo }
  ^^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, value, operator_loc) ⇒ AssocSplatNode

Initialize a new AssocSplatNode node.

: (Source source, Integer node_id, Location location, Integer flags, Prism::node? value, Location operator_loc) -> void

Parameters:

  • source (Source)
  • node_id (Integer)
  • location (Location)
  • flags (Integer)
  • value (Prism::node, nil)
  • operator_loc (Location)


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

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

Class Method Details

.type ⇒ :assoc_splat_node

See Node.type.

: () -> :assoc_splat_node

Returns:

  • (:assoc_splat_node)


2324
2325
2326
# File 'lib/prism/node.rb', line 2324

def self.type
  :assoc_splat_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


2396
2397
2398
2399
2400
# File 'lib/prism/node.rb', line 2396

def ===(other) # :nodoc:
  other.is_a?(AssocSplatNode) &&
    (value === other.value) &&
    (operator_loc.nil? == other.operator_loc.nil?)
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


2257
2258
2259
# File 'lib/prism/node.rb', line 2257

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

#child_nodes ⇒ Array[node?] Also known as: deconstruct

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


2264
2265
2266
# File 'lib/prism/node.rb', line 2264

def child_nodes
  [value]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


2281
2282
2283
2284
2285
# File 'lib/prism/node.rb', line 2281

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  if (value = self.value); compact << value; end
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, operator_loc: self.operator_loc) ⇒ AssocSplatNode

:call-seq:

copy(**fields) -> AssocSplatNode

Creates a copy of self with the given fields, using self as the template.

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Prism::node?, ?operator_loc: Location) -> AssocSplatNode

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • value: (Prism::node, nil) (defaults to: self.value)
  • operator_loc: (Location) (defaults to: self.operator_loc)

Returns:



2293
2294
2295
# File 'lib/prism/node.rb', line 2293

def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, operator_loc: self.operator_loc)
  AssocSplatNode.new(source, node_id, location, flags, value, operator_loc)
end

#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]

: (Array? keys) -> Hash[Symbol, untyped]

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
# File 'lib/prism/node.rb', line 2300

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location value operator_loc operator]).each_with_object(
    {} #: Hash[Symbol, untyped]
  ) do |key, deconstructed|
    case key
    when :node_id                 then deconstructed[:node_id] = self.node_id
    when :location                then deconstructed[:location] = self.location
    when :value                   then deconstructed[:value] = self.value
    when :operator_loc            then deconstructed[:operator_loc] = self.operator_loc
    when :operator                then deconstructed[:operator] = self.operator
    end
  end
end

#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void

See Node.each_child_node.

: () -> Enumerator[node, void] : () { (node) -> void } -> void

Overloads:

  • #each_child_node ⇒ Enumerator[node, void]

    Returns:

    • (Enumerator[node, void])
  • #each_child_node ⇒ void

    This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (node)

Yield Returns:

  • (void)


2272
2273
2274
2275
2276
# File 'lib/prism/node.rb', line 2272

def each_child_node(&blk)
  return to_enum(:each_child_node) unless block_given?

  if (value = self.value); yield value; end
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


2329
2330
2331
# File 'lib/prism/node.rb', line 2329

def inspect # :nodoc:
  InspectVisitor.compose(self)
end

#operator ⇒ String

:call-seq:

operator -> String

Slice the location of operator_loc from the source.

: () -> String

Returns:

  • (String)


2389
2390
2391
# File 'lib/prism/node.rb', line 2389

def operator
  operator_loc.slice
end

#operator_loc ⇒ Location

:category: Locations :call-seq:

operator_loc -> Location

The Location of the ** operator.

{ **x }
  ^^

Explore code sample

: () -> Location

Returns:



2366
2367
2368
2369
2370
# File 'lib/prism/node.rb', line 2366

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

#save_operator_loc(repository) ⇒ Relocation::Entry

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

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



2377
2378
2379
# File 'lib/prism/node.rb', line 2377

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

#type ⇒ :assoc_splat_node

See Node#type.

: () -> :assoc_splat_node

Returns:

  • (:assoc_splat_node)


2317
2318
2319
# File 'lib/prism/node.rb', line 2317

def type
  :assoc_splat_node
end

#value ⇒ Prism::node?

:call-seq:

value -> Node | nil

The value to be splatted, if present. Will be missing when keyword rest argument forwarding is used.

{ **foo }
    ^^^

Explore code sample

: () -> Prism::node?

Returns:

  • (Prism::node, nil)


2348
2349
2350
# File 'lib/prism/node.rb', line 2348

def value
  @value
end