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.



8098
8099
8100
8101
8102
# File 'lib/syntax_tree.rb', line 8098

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



8096
8097
8098
# File 'lib/syntax_tree.rb', line 8096

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



8093
8094
8095
# File 'lib/syntax_tree.rb', line 8093

def location
  @location
end

#partsObject (readonly)

Array the parts that are being assigned



8090
8091
8092
# File 'lib/syntax_tree.rb', line 8090

def parts
  @parts
end

Instance Method Details

#child_nodesObject



8104
8105
8106
# File 'lib/syntax_tree.rb', line 8104

def child_nodes
  parts
end

#format(q) ⇒ Object



8108
8109
8110
# File 'lib/syntax_tree.rb', line 8108

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

#pretty_print(q) ⇒ Object



8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
# File 'lib/syntax_tree.rb', line 8112

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



8123
8124
8125
8126
8127
# File 'lib/syntax_tree.rb', line 8123

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