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.



8434
8435
8436
8437
8438
# File 'lib/syntax_tree.rb', line 8434

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



8432
8433
8434
# File 'lib/syntax_tree.rb', line 8432

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



8429
8430
8431
# File 'lib/syntax_tree.rb', line 8429

def location
  @location
end

#partsObject (readonly)

Array the parts that are being assigned



8426
8427
8428
# File 'lib/syntax_tree.rb', line 8426

def parts
  @parts
end

Instance Method Details

#child_nodesObject



8440
8441
8442
# File 'lib/syntax_tree.rb', line 8440

def child_nodes
  parts
end

#format(q) ⇒ Object



8444
8445
8446
# File 'lib/syntax_tree.rb', line 8444

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

#pretty_print(q) ⇒ Object



8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
# File 'lib/syntax_tree.rb', line 8448

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



8459
8460
8461
8462
8463
# File 'lib/syntax_tree.rb', line 8459

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