Class: Prism::MatchWriteNode

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

Overview

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

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initialize a new MatchWriteNode node.



12889
12890
12891
12892
12893
12894
12895
12896
# File 'lib/prism/node.rb', line 12889

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

Instance Attribute Details

#callObject (readonly)

attr_reader call: CallNode



12932
12933
12934
# File 'lib/prism/node.rb', line 12932

def call
  @call
end

#targetsObject (readonly)

attr_reader targets: Array



12935
12936
12937
# File 'lib/prism/node.rb', line 12935

def targets
  @targets
end

Class Method Details

.typeObject

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



12948
12949
12950
# File 'lib/prism/node.rb', line 12948

def self.type
  :match_write_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.



12954
12955
12956
12957
12958
12959
# File 'lib/prism/node.rb', line 12954

def ===(other)
  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

def accept: (Visitor visitor) -> void



12899
12900
12901
# File 'lib/prism/node.rb', line 12899

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



12904
12905
12906
# File 'lib/prism/node.rb', line 12904

def child_nodes
  [call, *targets]
end

#comment_targetsObject

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



12914
12915
12916
# File 'lib/prism/node.rb', line 12914

def comment_targets
  [call, *targets] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



12909
12910
12911
# File 'lib/prism/node.rb', line 12909

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) ⇒ Object

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



12919
12920
12921
# File 'lib/prism/node.rb', line 12919

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) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, call: CallNode, targets: Array }



12927
12928
12929
# File 'lib/prism/node.rb', line 12927

def deconstruct_keys(keys)
  { node_id: node_id, location: location, call: call, targets: targets }
end

#inspectObject

def inspect -> String



12938
12939
12940
# File 'lib/prism/node.rb', line 12938

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



12943
12944
12945
# File 'lib/prism/node.rb', line 12943

def type
  :match_write_node
end