Class: Prism::MatchWriteNode

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

Overview

Represents writing local variables using a regular expression match with named capture groups.

/(?<foo>bar)/ =~ baz
^^^^^^^^^^^^^^^^^^^^

Explore code sample

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, call, targets) ⇒ MatchWriteNode

Initialize a new MatchWriteNode node.

: (Source source, Integer node_id, Location location, Integer flags, CallNode call, Array targets) -> void

Parameters:



23427
23428
23429
23430
23431
23432
23433
23434
# File 'lib/prism/node.rb', line 23427

def initialize(source, node_id, location, flags, call, targets)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @call = call
  @targets = targets
end

Class Method Details

.type ⇒ :match_write_node

See Node.type.

: () -> :match_write_node

Returns:



23515
23516
23517
# File 'lib/prism/node.rb', line 23515

def self.type
  :match_write_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

Returns:



23551
23552
23553
23554
23555
23556
# File 'lib/prism/node.rb', line 23551

def ===(other) # :nodoc:
  other.is_a?(MatchWriteNode) &&
    (call === other.call) &&
    (targets.length == other.targets.length) &&
    targets.zip(other.targets).all? { |left, right| left === right }
end

#accept(visitor) ⇒ Object

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:



23450
23451
23452
# File 'lib/prism/node.rb', line 23450

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

#call ⇒ CallNode

:call-seq:

call -> CallNode

Returns the call attribute.

: () -> CallNode

Returns:



23532
23533
23534
# File 'lib/prism/node.rb', line 23532

def call
  @call
end

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

See Node.child_nodes.

: () -> Array

Returns:



23457
23458
23459
# File 'lib/prism/node.rb', line 23457

def child_nodes
  [call, *targets]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:



23475
23476
23477
# File 'lib/prism/node.rb', line 23475

def compact_child_nodes
  [call, *targets]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, call: self.call, targets: self.targets) ⇒ MatchWriteNode

:call-seq:

copy(**fields) -> MatchWriteNode

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

: (?node_id: Integer, ?location: Location, ?flags: Integer, ?call: CallNode, ?targets: Array) -> MatchWriteNode

Parameters:

  • (defaults to: self.node_id)
  • (defaults to: self.location)
  • (defaults to: self.flags)
  • (defaults to: self.call)
  • (defaults to: self.targets)

Returns:



23485
23486
23487
# File 'lib/prism/node.rb', line 23485

def copy(node_id: self.node_id, location: self.location, flags: self.flags, call: self.call, targets: self.targets)
  MatchWriteNode.new(source, node_id, location, flags, call, targets)
end

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

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

Parameters:

Returns:



23492
23493
23494
23495
23496
23497
23498
23499
23500
23501
23502
23503
# File 'lib/prism/node.rb', line 23492

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location call targets]).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 :call                    then deconstructed[:call] = self.call
    when :targets                 then deconstructed[:targets] = self.targets
    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:

  • #each_child_node ⇒ void

    This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (node)

Yield Returns:

  • (void)


23465
23466
23467
23468
23469
23470
# File 'lib/prism/node.rb', line 23465

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

  yield call
  targets.each { |node| yield node }
end

#inspect ⇒ String

: () -> String

Returns:



23520
23521
23522
# File 'lib/prism/node.rb', line 23520

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

#targets ⇒ Array[LocalVariableTargetNode]

:call-seq:

targets -> Array[LocalVariableTargetNode]

Returns the targets attribute.

: () -> Array

Returns:



23542
23543
23544
# File 'lib/prism/node.rb', line 23542

def targets
  @targets
end

#type ⇒ :match_write_node

See Node#type.

: () -> :match_write_node

Returns:



23508
23509
23510
# File 'lib/prism/node.rb', line 23508

def type
  :match_write_node
end