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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(parts:, location:, comments: []) ⇒ Word
Returns a new instance of Word.
9854 9855 9856 9857 9858 |
# File 'lib/syntax_tree/node.rb', line 9854 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
9852 9853 9854 |
# File 'lib/syntax_tree/node.rb', line 9852 def comments @comments end |
#parts ⇒ Object (readonly)
[Array[ StringEmbExpr | StringDVar | TStringContent ]] the parts of the word
9849 9850 9851 |
# File 'lib/syntax_tree/node.rb', line 9849 def parts @parts end |
Instance Method Details
#accept(visitor) ⇒ Object
9864 9865 9866 |
# File 'lib/syntax_tree/node.rb', line 9864 def accept(visitor) visitor.visit_word(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9868 9869 9870 |
# File 'lib/syntax_tree/node.rb', line 9868 def child_nodes parts end |
#deconstruct_keys(_keys) ⇒ Object
9874 9875 9876 |
# File 'lib/syntax_tree/node.rb', line 9874 def deconstruct_keys(_keys) { parts: parts, location: location, comments: comments } end |
#format(q) ⇒ Object
9878 9879 9880 |
# File 'lib/syntax_tree/node.rb', line 9878 def format(q) q.format_each(parts) end |
#match?(pattern) ⇒ Boolean
9860 9861 9862 |
# File 'lib/syntax_tree/node.rb', line 9860 def match?(pattern) parts.any? { |part| part.is_a?(TStringContent) && part.match?(pattern) } end |