Class: SyntaxTree::Word
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::Word
show all
- Defined in:
- lib/syntax_tree/node.rb
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
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(parts:, location:) ⇒ Word
11843
11844
11845
11846
11847
|
# File 'lib/syntax_tree/node.rb', line 11843
def initialize(parts:, location:)
@parts = parts
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11841
11842
11843
|
# File 'lib/syntax_tree/node.rb', line 11841
def
end
|
#parts ⇒ Object
- 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..concat(.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: }
end
|
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
|