class SyntaxTree::Word
Word
represents an element within a special array literal that accepts interpolation.
%W[a#{b}c xyz]
In
the example above, there would be two Word
nodes within a parent Words
node.
Attributes
parts[R]
- Array[
StringEmbExpr
|StringDVar
|TStringContent
] -
the parts of the
word
Public Class Methods
new(parts:, location:)
click to toggle source
# File lib/syntax_tree/node.rb, line 12012 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 12051 def ===(other) other.is_a?(Word) && ArrayMatch.call(parts, other.parts) end
accept(visitor)
click to toggle source
# File lib/syntax_tree/node.rb, line 12022 def accept(visitor) visitor.visit_word(self) end
child_nodes()
click to toggle source
# File lib/syntax_tree/node.rb, line 12026 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 12030 def copy(parts: nil, location: nil) node = Word.new( parts: parts || self.parts, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end
deconstruct_keys(_keys)
click to toggle source
# File lib/syntax_tree/node.rb, line 12043 def deconstruct_keys(_keys) { parts: parts, location: location, comments: comments } end
format(q)
click to toggle source
# File lib/syntax_tree/node.rb, line 12047 def format(q) q.format_each(parts) end
match?(pattern)
click to toggle source
# File lib/syntax_tree/node.rb, line 12018 def match?(pattern) parts.any? { |part| part.is_a?(TStringContent) && part.match?(pattern) } end