Class: SyntaxTree::Comment
Overview
Comment represents a comment in the source.
# comment
Defined Under Namespace
Classes: List
Instance Attribute Summary collapse
-
#inline ⇒ Object
(also: #inline?)
readonly
- boolean
-
whether or not there is code on the same line as this comment.
-
#value ⇒ Object
readonly
- String
-
the contents of the comment.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #comments ⇒ Object
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
- #ignore? ⇒ Boolean
-
#initialize(value:, inline:, location:) ⇒ Comment
constructor
A new instance of Comment.
- #leading! ⇒ Object
- #leading? ⇒ Boolean
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
- #trailing! ⇒ Object
- #trailing? ⇒ Boolean
Constructor Details
#initialize(value:, inline:, location:) ⇒ Comment
Returns a new instance of Comment.
3327 3328 3329 3330 3331 3332 3333 3334 |
# File 'lib/syntax_tree/node.rb', line 3327 def initialize(value:, inline:, location:) @value = value @inline = inline @location = location @leading = false @trailing = false end |
Instance Attribute Details
#inline ⇒ Object (readonly) Also known as: inline?
- boolean
-
whether or not there is code on the same line as this comment.
If there is, then inline will be true.
3324 3325 3326 |
# File 'lib/syntax_tree/node.rb', line 3324 def inline @inline end |
#value ⇒ Object (readonly)
- String
-
the contents of the comment
3320 3321 3322 |
# File 'lib/syntax_tree/node.rb', line 3320 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
3360 3361 3362 |
# File 'lib/syntax_tree/node.rb', line 3360 def child_nodes [] end |
#comments ⇒ Object
3356 3357 3358 |
# File 'lib/syntax_tree/node.rb', line 3356 def comments [] end |
#deconstruct_keys(keys) ⇒ Object
3366 3367 3368 |
# File 'lib/syntax_tree/node.rb', line 3366 def deconstruct_keys(keys) { value: value, inline: inline, location: location } end |
#format(q) ⇒ Object
3370 3371 3372 |
# File 'lib/syntax_tree/node.rb', line 3370 def format(q) q.text(value) end |
#ignore? ⇒ Boolean
3352 3353 3354 |
# File 'lib/syntax_tree/node.rb', line 3352 def ignore? value[1..-1].strip == "stree-ignore" end |
#leading! ⇒ Object
3336 3337 3338 |
# File 'lib/syntax_tree/node.rb', line 3336 def leading! @leading = true end |
#leading? ⇒ Boolean
3340 3341 3342 |
# File 'lib/syntax_tree/node.rb', line 3340 def leading? @leading end |
#pretty_print(q) ⇒ Object
3374 3375 3376 3377 3378 3379 3380 3381 |
# File 'lib/syntax_tree/node.rb', line 3374 def pretty_print(q) q.group(2, "(", ")") do q.text("comment") q.breakable q.pp(value) end end |
#to_json(*opts) ⇒ Object
3383 3384 3385 3386 3387 3388 3389 3390 |
# File 'lib/syntax_tree/node.rb', line 3383 def to_json(*opts) { type: :comment, value: value.force_encoding("UTF-8"), inline: inline, loc: location }.to_json(*opts) end |
#trailing! ⇒ Object
3344 3345 3346 |
# File 'lib/syntax_tree/node.rb', line 3344 def trailing! @trailing = true end |
#trailing? ⇒ Boolean
3348 3349 3350 |
# File 'lib/syntax_tree/node.rb', line 3348 def trailing? @trailing end |