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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#value ⇒ Object
readonly
- String
-
the contents of the comment.
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.
3432 3433 3434 3435 3436 3437 3438 3439 |
# File 'lib/syntax_tree/node.rb', line 3432 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.
3426 3427 3428 |
# File 'lib/syntax_tree/node.rb', line 3426 def inline @inline end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
3430 3431 3432 |
# File 'lib/syntax_tree/node.rb', line 3430 def location @location end |
#value ⇒ Object (readonly)
- String
-
the contents of the comment
3422 3423 3424 |
# File 'lib/syntax_tree/node.rb', line 3422 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
3465 3466 3467 |
# File 'lib/syntax_tree/node.rb', line 3465 def child_nodes [] end |
#comments ⇒ Object
3461 3462 3463 |
# File 'lib/syntax_tree/node.rb', line 3461 def comments [] end |
#deconstruct_keys(keys) ⇒ Object
3471 3472 3473 |
# File 'lib/syntax_tree/node.rb', line 3471 def deconstruct_keys(keys) { value: value, inline: inline, location: location } end |
#format(q) ⇒ Object
3475 3476 3477 |
# File 'lib/syntax_tree/node.rb', line 3475 def format(q) q.text(value) end |
#ignore? ⇒ Boolean
3457 3458 3459 |
# File 'lib/syntax_tree/node.rb', line 3457 def ignore? value[1..-1].strip == "stree-ignore" end |
#leading! ⇒ Object
3441 3442 3443 |
# File 'lib/syntax_tree/node.rb', line 3441 def leading! @leading = true end |
#leading? ⇒ Boolean
3445 3446 3447 |
# File 'lib/syntax_tree/node.rb', line 3445 def leading? @leading end |
#pretty_print(q) ⇒ Object
3479 3480 3481 3482 3483 3484 3485 3486 |
# File 'lib/syntax_tree/node.rb', line 3479 def pretty_print(q) q.group(2, "(", ")") do q.text("comment") q.breakable q.pp(value) end end |
#to_json(*opts) ⇒ Object
3488 3489 3490 3491 3492 3493 3494 3495 |
# File 'lib/syntax_tree/node.rb', line 3488 def to_json(*opts) { type: :comment, value: value.force_encoding("UTF-8"), inline: inline, loc: location }.to_json(*opts) end |
#trailing! ⇒ Object
3449 3450 3451 |
# File 'lib/syntax_tree/node.rb', line 3449 def trailing! @trailing = true end |
#trailing? ⇒ Boolean
3453 3454 3455 |
# File 'lib/syntax_tree/node.rb', line 3453 def trailing? @trailing end |