class SyntaxTree::DynaSymbol

DynaSymbol represents a symbol literal that uses quotes to dynamically define its value.

:"#{variable}"

They can also be used as a special kind of dynamic hash key, as in:

{ "#{key}": value }

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

parts[R]
Array[ StringDVar | StringEmbExpr | TStringContent ]

the parts of the

dynamic symbol

quote[R]
nil | String

the quote used to delimit the dynamic symbol

Public Class Methods

new(parts:, quote:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 4674
def initialize(parts:, quote:, location:)
  @parts = parts
  @quote = quote
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 4736
def ===(other)
  other.is_a?(DynaSymbol) && ArrayMatch.call(parts, other.parts) &&
    quote === other.quote
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 4681
def accept(visitor)
  visitor.visit_dyna_symbol(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 4685
def child_nodes
  parts
end
Also aliased as: deconstruct
copy(parts: nil, quote: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 4689
def copy(parts: nil, quote: nil, location: nil)
  node =
    DynaSymbol.new(
      parts: parts || self.parts,
      quote: quote || self.quote,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 4703
def deconstruct_keys(_keys)
  { parts: parts, quote: quote, location: location, comments: comments }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 4707
def format(q)
  opening_quote, closing_quote = quotes(q)

  q.text(opening_quote)
  q.group do
    parts.each do |part|
      if part.is_a?(TStringContent)
        value = Quotes.normalize(part.value, closing_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(closing_quote)
end