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
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(parts: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parts:, location:) ⇒ 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:) ⇒ Word
Returns a new instance of Word.
11843 11844 11845 11846 11847 |
# File 'lib/syntax_tree/node.rb', line 11843 def initialize(parts:, location:) @parts = parts @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11841 11842 11843 |
# File 'lib/syntax_tree/node.rb', line 11841 def comments @comments end |
#parts ⇒ Object (readonly)
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the
word
11838 11839 11840 |
# File 'lib/syntax_tree/node.rb', line 11838 def parts @parts end |
Instance Method Details
#===(other) ⇒ Object
11882 11883 11884 |
# File 'lib/syntax_tree/node.rb', line 11882 def ===(other) other.is_a?(Word) && ArrayMatch.call(parts, other.parts) end |
#accept(visitor) ⇒ Object
11853 11854 11855 |
# File 'lib/syntax_tree/node.rb', line 11853 def accept(visitor) visitor.visit_word(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
11857 11858 11859 |
# File 'lib/syntax_tree/node.rb', line 11857 def child_nodes parts end |
#copy(parts: nil, location: nil) ⇒ Object
11861 11862 11863 11864 11865 11866 11867 11868 11869 11870 |
# File 'lib/syntax_tree/node.rb', line 11861 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) ⇒ Object
11874 11875 11876 |
# File 'lib/syntax_tree/node.rb', line 11874 def deconstruct_keys(_keys) { parts: parts, location: location, comments: comments } end |
#format(q) ⇒ Object
11878 11879 11880 |
# File 'lib/syntax_tree/node.rb', line 11878 def format(q) q.format_each(parts) end |
#match?(pattern) ⇒ Boolean
11849 11850 11851 |
# File 'lib/syntax_tree/node.rb', line 11849 def match?(pattern) parts.any? { |part| part.is_a?(TStringContent) && part.match?(pattern) } end |