Class: SyntaxTree::MRHS

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.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

Instance Method Summary collapse

Constructor Details

#initialize(parts:, location:, comments: []) ⇒ MRHS

Returns a new instance of MRHS.



8511
8512
8513
8514
8515
# File 'lib/syntax_tree.rb', line 8511

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8509
8510
8511
# File 'lib/syntax_tree.rb', line 8509

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



8506
8507
8508
# File 'lib/syntax_tree.rb', line 8506

def location
  @location
end

#partsObject (readonly)

Array the parts that are being assigned



8503
8504
8505
# File 'lib/syntax_tree.rb', line 8503

def parts
  @parts
end

Instance Method Details

#child_nodesObject



8517
8518
8519
# File 'lib/syntax_tree.rb', line 8517

def child_nodes
  parts
end

#format(q) ⇒ Object



8521
8522
8523
# File 'lib/syntax_tree.rb', line 8521

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

#pretty_print(q) ⇒ Object



8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
# File 'lib/syntax_tree.rb', line 8525

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("mrhs")

    q.breakable
    q.group(2, "(", ")") { q.seplist(parts) { |part| q.pp(part) } }

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



8536
8537
8538
8539
8540
# File 'lib/syntax_tree.rb', line 8536

def to_json(*opts)
  { type: :mrhs, parts: parts, loc: location, cmts: comments }.to_json(
    *opts
  )
end