Class: SyntaxTree::Word
- Inherits:
-
Object
- Object
- SyntaxTree::Word
- Defined in:
- lib/syntax_tree.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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#parts ⇒ Object
readonly
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the word.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parts:, location:, comments: []) ⇒ Word
constructor
A new instance of Word.
- #match?(pattern) ⇒ Boolean
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(parts:, location:, comments: []) ⇒ Word
Returns a new instance of Word.
13239 13240 13241 13242 13243 |
# File 'lib/syntax_tree.rb', line 13239 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
13237 13238 13239 |
# File 'lib/syntax_tree.rb', line 13237 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
13234 13235 13236 |
# File 'lib/syntax_tree.rb', line 13234 def location @location end |
#parts ⇒ Object (readonly)
- Array[ StringEmbExpr | StringDVar | TStringContent ]
-
the parts of the
word
13231 13232 13233 |
# File 'lib/syntax_tree.rb', line 13231 def parts @parts end |
Instance Method Details
#child_nodes ⇒ Object
13249 13250 13251 |
# File 'lib/syntax_tree.rb', line 13249 def child_nodes parts end |
#format(q) ⇒ Object
13253 13254 13255 |
# File 'lib/syntax_tree.rb', line 13253 def format(q) q.format_each(parts) end |
#match?(pattern) ⇒ Boolean
13245 13246 13247 |
# File 'lib/syntax_tree.rb', line 13245 def match?(pattern) parts.any? { |part| part.is_a?(TStringContent) && part.match?(pattern) } end |
#pretty_print(q) ⇒ Object
13257 13258 13259 13260 13261 13262 13263 13264 13265 13266 |
# File 'lib/syntax_tree.rb', line 13257 def pretty_print(q) q.group(2, "(", ")") do q.text("word") q.breakable q.group(2, "(", ")") { q.seplist(parts) { |part| q.pp(part) } } q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
13268 13269 13270 13271 13272 |
# File 'lib/syntax_tree.rb', line 13268 def to_json(*opts) { type: :word, parts: parts, loc: location, cmts: comments }.to_json( *opts ) end |