Class: SyntaxTree::Paren
Overview
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)
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#contents ⇒ Object
readonly
- nil | untyped
-
the expression inside the parentheses.
-
#lparen ⇒ Object
readonly
- LParen
-
the left parenthesis that opened this statement.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(lparen:, contents:, location:, comments: []) ⇒ Paren
constructor
A new instance of Paren.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(lparen:, contents:, location:, comments: []) ⇒ Paren
Returns a new instance of Paren.
7000 7001 7002 7003 7004 7005 |
# File 'lib/syntax_tree/node.rb', line 7000 def initialize(lparen:, contents:, location:, comments: []) @lparen = lparen @contents = contents @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6998 6999 7000 |
# File 'lib/syntax_tree/node.rb', line 6998 def comments @comments end |
#contents ⇒ Object (readonly)
- nil | untyped
-
the expression inside the parentheses
6995 6996 6997 |
# File 'lib/syntax_tree/node.rb', line 6995 def contents @contents end |
#lparen ⇒ Object (readonly)
- LParen
-
the left parenthesis that opened this statement
6992 6993 6994 |
# File 'lib/syntax_tree/node.rb', line 6992 def lparen @lparen end |
Instance Method Details
#accept(visitor) ⇒ Object
7007 7008 7009 |
# File 'lib/syntax_tree/node.rb', line 7007 def accept(visitor) visitor.visit_paren(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7011 7012 7013 |
# File 'lib/syntax_tree/node.rb', line 7011 def child_nodes [lparen, contents] end |
#deconstruct_keys(_keys) ⇒ Object
7017 7018 7019 7020 7021 7022 7023 7024 |
# File 'lib/syntax_tree/node.rb', line 7017 def deconstruct_keys(_keys) { lparen: lparen, contents: contents, location: location, comments: comments } end |
#format(q) ⇒ Object
7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 |
# File 'lib/syntax_tree/node.rb', line 7026 def format(q) q.group do q.format(lparen) if contents && (!contents.is_a?(Params) || !contents.empty?) q.indent do q.breakable("") q.format(contents) end end q.breakable("") q.text(")") end end |