Class: SyntaxTree::MRHS

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

MRHS represents the values that are being assigned on the right-hand side of a multiple assignment.

values = first, second, third

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(parts:, location:) ⇒ MRHS

Returns a new instance of MRHS.



7866
7867
7868
7869
7870
# File 'lib/syntax_tree/node.rb', line 7866

def initialize(parts:, location:)
  @parts = parts
  @location = location
  @comments = []
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



7864
7865
7866
# File 'lib/syntax_tree/node.rb', line 7864

def comments
  @comments
end

#partsObject (readonly)

Array

the parts that are being assigned



7861
7862
7863
# File 'lib/syntax_tree/node.rb', line 7861

def parts
  @parts
end

Instance Method Details

#===(other) ⇒ Object



7901
7902
7903
# File 'lib/syntax_tree/node.rb', line 7901

def ===(other)
  other.is_a?(MRHS) && ArrayMatch.call(parts, other.parts)
end

#accept(visitor) ⇒ Object



7872
7873
7874
# File 'lib/syntax_tree/node.rb', line 7872

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

#child_nodesObject Also known as: deconstruct



7876
7877
7878
# File 'lib/syntax_tree/node.rb', line 7876

def child_nodes
  parts
end

#copy(parts: nil, location: nil) ⇒ Object



7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
# File 'lib/syntax_tree/node.rb', line 7880

def copy(parts: nil, location: nil)
  node =
    MRHS.new(
      parts: parts || self.parts,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



7893
7894
7895
# File 'lib/syntax_tree/node.rb', line 7893

def deconstruct_keys(_keys)
  { parts: parts, location: location, comments: comments }
end

#format(q) ⇒ Object



7897
7898
7899
# File 'lib/syntax_tree/node.rb', line 7897

def format(q)
  q.seplist(parts) { |part| q.format(part) }
end