Class: SyntaxTree::StringConcat
Overview
StringConcat represents concatenating two strings together using a backward slash.
"first" \
"second"
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#left ⇒ Object
readonly
- StringConcat | StringLiteral
-
the left side of the concatenation.
-
#right ⇒ Object
readonly
- StringLiteral
-
the right side of the concatenation.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(left:, right:, location:, comments: []) ⇒ StringConcat
constructor
A new instance of StringConcat.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(left:, right:, location:, comments: []) ⇒ StringConcat
Returns a new instance of StringConcat.
9204 9205 9206 9207 9208 9209 |
# File 'lib/syntax_tree/node.rb', line 9204 def initialize(left:, right:, location:, comments: []) @left = left @right = right @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9202 9203 9204 |
# File 'lib/syntax_tree/node.rb', line 9202 def comments @comments end |
#left ⇒ Object (readonly)
- StringConcat | StringLiteral
-
the left side of the concatenation
9196 9197 9198 |
# File 'lib/syntax_tree/node.rb', line 9196 def left @left end |
#right ⇒ Object (readonly)
- StringLiteral
-
the right side of the concatenation
9199 9200 9201 |
# File 'lib/syntax_tree/node.rb', line 9199 def right @right end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
9211 9212 9213 |
# File 'lib/syntax_tree/node.rb', line 9211 def child_nodes [left, right] end |
#deconstruct_keys(keys) ⇒ Object
9217 9218 9219 |
# File 'lib/syntax_tree/node.rb', line 9217 def deconstruct_keys(keys) { left: left, right: right, location: location, comments: comments } end |
#format(q) ⇒ Object
9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 |
# File 'lib/syntax_tree/node.rb', line 9221 def format(q) q.group do q.format(left) q.text(' \\') q.indent do q.breakable(force: true) q.format(right) end end end |
#pretty_print(q) ⇒ Object
9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 |
# File 'lib/syntax_tree/node.rb', line 9232 def pretty_print(q) q.group(2, "(", ")") do q.text("string_concat") q.breakable q.pp(left) q.breakable q.pp(right) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
9246 9247 9248 9249 9250 9251 9252 9253 9254 |
# File 'lib/syntax_tree/node.rb', line 9246 def to_json(*opts) { type: :string_concat, left: left, right: right, loc: location, cmts: comments }.to_json(*opts) end |