class SyntaxTree::Paren

Paren represents using balanced parentheses in a couple places in a Ruby program. In general parentheses can be used anywhere a Ruby expression can be used.

(1 + 2)

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

contents[R]
nil | Node

the expression inside the parentheses

lparen[R]
LParen

the left parenthesis that opened this statement

Public Class Methods

new(lparen:, contents:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 8489
def initialize(lparen:, contents:, location:)
  @lparen = lparen
  @contents = contents
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 8545
def ===(other)
  other.is_a?(Paren) && lparen === other.lparen &&
    contents === other.contents
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 8496
def accept(visitor)
  visitor.visit_paren(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 8500
def child_nodes
  [lparen, contents]
end
Also aliased as: deconstruct
copy(lparen: nil, contents: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 8504
def copy(lparen: nil, contents: nil, location: nil)
  node =
    Paren.new(
      lparen: lparen || self.lparen,
      contents: contents || self.contents,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 8518
def deconstruct_keys(_keys)
  {
    lparen: lparen,
    contents: contents,
    location: location,
    comments: comments
  }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 8527
def format(q)
  contents = self.contents

  q.group do
    q.format(lparen)

    if contents && (!contents.is_a?(Params) || !contents.empty?)
      q.indent do
        q.breakable_empty
        q.format(contents)
      end
    end

    q.breakable_empty
    q.text(")")
  end
end