Class: SyntaxTree::Word
Overview
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.
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 word.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parts:, location:, comments: []) ⇒ Word
constructor
A new instance of Word.
- #match?(pattern) ⇒ Boolean
Methods inherited from Node
Constructor Details
#initialize(parts:, location:, comments: []) ⇒ Word
Returns a new instance of Word.
9631 9632 9633 9634 9635 |
# File 'lib/syntax_tree/node.rb', line 9631 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
9629 9630 9631 |
# File 'lib/syntax_tree/node.rb', line 9629 def comments @comments end |
#parts ⇒ Object (readonly)
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the
word
9626 9627 9628 |
# File 'lib/syntax_tree/node.rb', line 9626 def parts @parts end |
Instance Method Details
#accept(visitor) ⇒ Object
9641 9642 9643 |
# File 'lib/syntax_tree/node.rb', line 9641 def accept(visitor) visitor.visit_word(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9645 9646 9647 |
# File 'lib/syntax_tree/node.rb', line 9645 def child_nodes parts end |
#deconstruct_keys(keys) ⇒ Object
9651 9652 9653 |
# File 'lib/syntax_tree/node.rb', line 9651 def deconstruct_keys(keys) { parts: parts, location: location, comments: comments } end |
#format(q) ⇒ Object
9655 9656 9657 |
# File 'lib/syntax_tree/node.rb', line 9655 def format(q) q.format_each(parts) end |
#match?(pattern) ⇒ Boolean
9637 9638 9639 |
# File 'lib/syntax_tree/node.rb', line 9637 def match?(pattern) parts.any? { |part| part.is_a?(TStringContent) && part.match?(pattern) } end |