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, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(parts:, location:) ⇒ Word
Returns a new instance of Word.
11995 11996 11997 11998 11999 |
# File 'lib/syntax_tree/node.rb', line 11995 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
11993 11994 11995 |
# File 'lib/syntax_tree/node.rb', line 11993 def comments @comments end |
#parts ⇒ Object (readonly)
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the
word
11990 11991 11992 |
# File 'lib/syntax_tree/node.rb', line 11990 def parts @parts end |
Instance Method Details
#===(other) ⇒ Object
12034 12035 12036 |
# File 'lib/syntax_tree/node.rb', line 12034 def ===(other) other.is_a?(Word) && ArrayMatch.call(parts, other.parts) end |
#accept(visitor) ⇒ Object
12005 12006 12007 |
# File 'lib/syntax_tree/node.rb', line 12005 def accept(visitor) visitor.visit_word(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
12009 12010 12011 |
# File 'lib/syntax_tree/node.rb', line 12009 def child_nodes parts end |
#copy(parts: nil, location: nil) ⇒ Object
12013 12014 12015 12016 12017 12018 12019 12020 12021 12022 |
# File 'lib/syntax_tree/node.rb', line 12013 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
12026 12027 12028 |
# File 'lib/syntax_tree/node.rb', line 12026 def deconstruct_keys(_keys) { parts: parts, location: location, comments: comments } end |
#format(q) ⇒ Object
12030 12031 12032 |
# File 'lib/syntax_tree/node.rb', line 12030 def format(q) q.format_each(parts) end |
#match?(pattern) ⇒ Boolean
12001 12002 12003 |
# File 'lib/syntax_tree/node.rb', line 12001 def match?(pattern) parts.any? { |part| part.is_a?(TStringContent) && part.match?(pattern) } end |