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
- nil |
Node
-
the expression inside the parentheses
LParen
-
the left parenthesis that opened this statement
Public Class Methods
Source
# File lib/syntax_tree/node.rb, line 8504 def initialize(lparen:, contents:, location:) @lparen = lparen @contents = contents @location = location @comments = [] end
Public Instance Methods
Source
# File lib/syntax_tree/node.rb, line 8560 def ===(other) other.is_a?(Paren) && lparen === other.lparen && contents === other.contents end
Source
# File lib/syntax_tree/node.rb, line 8511 def accept(visitor) visitor.visit_paren(self) end
Source
# File lib/syntax_tree/node.rb, line 8515 def child_nodes [lparen, contents] end
Also aliased as: deconstruct
Source
# File lib/syntax_tree/node.rb, line 8519 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
Source
# File lib/syntax_tree/node.rb, line 8533 def deconstruct_keys(_keys) { lparen: lparen, contents: contents, location: location, comments: comments } end
Source
# File lib/syntax_tree/node.rb, line 8542 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