Class: SyntaxTree::MLHSParen

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

Overview

MLHSParen represents parentheses being used to destruct values in a multiple assignment on the left hand side.

(left, right) = value

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

#initialize(contents:, location:, comments: []) ⇒ MLHSParen

Returns a new instance of MLHSParen.



5598
5599
5600
5601
5602
# File 'lib/syntax_tree/node.rb', line 5598

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5596
5597
5598
# File 'lib/syntax_tree/node.rb', line 5596

def comments
  @comments
end

#contentsObject (readonly)

MLHS | MLHSParen

the contents inside of the parentheses



5593
5594
5595
# File 'lib/syntax_tree/node.rb', line 5593

def contents
  @contents
end

Instance Method Details

#accept(visitor) ⇒ Object



5604
5605
5606
# File 'lib/syntax_tree/node.rb', line 5604

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

#child_nodesObject Also known as: deconstruct



5608
5609
5610
# File 'lib/syntax_tree/node.rb', line 5608

def child_nodes
  [contents]
end

#deconstruct_keys(keys) ⇒ Object



5614
5615
5616
# File 'lib/syntax_tree/node.rb', line 5614

def deconstruct_keys(keys)
  { contents: contents, location: location, comments: comments }
end

#format(q) ⇒ Object



5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
# File 'lib/syntax_tree/node.rb', line 5618

def format(q)
  parent = q.parent

  if parent.is_a?(MAssign) || parent.is_a?(MLHSParen)
    q.format(contents)
  else
    q.group(0, "(", ")") do
      q.indent do
        q.breakable("")
        q.format(contents)
      end

      q.breakable("")
    end
  end
end