Class: SyntaxTree::XStringLiteral
Overview
XStringLiteral represents a string that gets executed.
`ls`
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
[Array[ Comment | EmbDoc ]] the comments attached to this node.
-
#parts ⇒ Object
readonly
[Array[ StringEmbExpr | StringDVar | TStringContent ]] the parts of the xstring.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parts:, location:, comments: []) ⇒ XStringLiteral
constructor
A new instance of XStringLiteral.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(parts:, location:, comments: []) ⇒ XStringLiteral
Returns a new instance of XStringLiteral.
11302 11303 11304 11305 11306 |
# File 'lib/syntax_tree/node.rb', line 11302 def initialize(parts:, location:, comments: []) @parts = parts @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
[Array[ Comment | EmbDoc ]] the comments attached to this node
11300 11301 11302 |
# File 'lib/syntax_tree/node.rb', line 11300 def comments @comments end |
#parts ⇒ Object (readonly)
[Array[ StringEmbExpr | StringDVar | TStringContent ]] the parts of the xstring
11297 11298 11299 |
# File 'lib/syntax_tree/node.rb', line 11297 def parts @parts end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
11308 11309 11310 |
# File 'lib/syntax_tree/node.rb', line 11308 def child_nodes parts end |
#deconstruct_keys(keys) ⇒ Object
11314 11315 11316 |
# File 'lib/syntax_tree/node.rb', line 11314 def deconstruct_keys(keys) { parts: parts, location: location, comments: comments } end |
#format(q) ⇒ Object
11318 11319 11320 11321 11322 |
# File 'lib/syntax_tree/node.rb', line 11318 def format(q) q.text("`") q.format_each(parts) q.text("`") end |
#pretty_print(q) ⇒ Object
11324 11325 11326 11327 11328 11329 11330 11331 11332 11333 |
# File 'lib/syntax_tree/node.rb', line 11324 def pretty_print(q) q.group(2, "(", ")") do q.text("xstring_literal") q.breakable q.group(2, "(", ")") { q.seplist(parts) { |part| q.pp(part) } } q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
11335 11336 11337 11338 11339 11340 11341 11342 |
# File 'lib/syntax_tree/node.rb', line 11335 def to_json(*opts) { type: :xstring_literal, parts: parts, loc: location, cmts: comments }.to_json(*opts) end |