class SyntaxTree::StringContent
StringContent
represents the contents of a string-like value.
"string"
Attributes
parts[R]
- Array[
StringEmbExpr
|StringDVar
|TStringContent
] -
the parts of the
string
Public Class Methods
new(parts:, location:)
click to toggle source
# File lib/syntax_tree/node.rb, line 10059 def initialize(parts:, location:) @parts = parts @location = location @comments = [] end
Public Instance Methods
===(other)
click to toggle source
# File lib/syntax_tree/node.rb, line 10086 def ===(other) other.is_a?(StringContent) && ArrayMatch.call(parts, other.parts) end
accept(visitor)
click to toggle source
# File lib/syntax_tree/node.rb, line 10065 def accept(visitor) visitor.visit_string_content(self) end
child_nodes()
click to toggle source
# File lib/syntax_tree/node.rb, line 10069 def child_nodes parts end
Also aliased as: deconstruct
copy(parts: nil, location: nil)
click to toggle source
# File lib/syntax_tree/node.rb, line 10073 def copy(parts: nil, location: nil) StringContent.new( parts: parts || self.parts, location: location || self.location ) end
deconstruct_keys(_keys)
click to toggle source
# File lib/syntax_tree/node.rb, line 10082 def deconstruct_keys(_keys) { parts: parts, location: location } end
format(q)
click to toggle source
# File lib/syntax_tree/node.rb, line 10090 def format(q) q.text(q.quote) q.group do parts.each do |part| if part.is_a?(TStringContent) value = Quotes.normalize(part.value, q.quote) first = true value.each_line(chomp: true) do |line| if first first = false else q.breakable_return end q.text(line) end q.breakable_return if value.end_with?("\n") else q.format(part) end end end q.text(q.quote) end