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
11873
11874
11875
11876
11877
|
# File 'lib/syntax_tree/node.rb', line 11873
def initialize(parts:, location:)
@parts = parts
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11871
11872
11873
|
# File 'lib/syntax_tree/node.rb', line 11871
def
end
|
#parts ⇒ Object
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the
word
11868
11869
11870
|
# File 'lib/syntax_tree/node.rb', line 11868
def parts
@parts
end
|
Instance Method Details
#===(other) ⇒ Object
11912
11913
11914
|
# File 'lib/syntax_tree/node.rb', line 11912
def ===(other)
other.is_a?(Word) && ArrayMatch.call(parts, other.parts)
end
|
#accept(visitor) ⇒ Object
11883
11884
11885
|
# File 'lib/syntax_tree/node.rb', line 11883
def accept(visitor)
visitor.visit_word(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
11887
11888
11889
|
# File 'lib/syntax_tree/node.rb', line 11887
def child_nodes
parts
end
|
#copy(parts: nil, location: nil) ⇒ Object
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
|
# File 'lib/syntax_tree/node.rb', line 11891
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
11904
11905
11906
|
# File 'lib/syntax_tree/node.rb', line 11904
def deconstruct_keys(_keys)
{ parts: parts, location: location, comments: }
end
|
11908
11909
11910
|
# File 'lib/syntax_tree/node.rb', line 11908
def format(q)
q.format_each(parts)
end
|
#match?(pattern) ⇒ Boolean
11879
11880
11881
|
# File 'lib/syntax_tree/node.rb', line 11879
def match?(pattern)
parts.any? { |part| part.is_a?(TStringContent) && part.match?(pattern) }
end
|