Class: SyntaxTree::Comment
- Inherits:
-
Object
- Object
- SyntaxTree::Comment
- Defined in:
- lib/syntax_tree.rb
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
- #comments ⇒ Object
- #format(q) ⇒ Object
-
#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.
3643 3644 3645 3646 3647 3648 3649 3650 |
# File 'lib/syntax_tree.rb', line 3643 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.
3637 3638 3639 |
# File 'lib/syntax_tree.rb', line 3637 def inline @inline end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
3641 3642 3643 |
# File 'lib/syntax_tree.rb', line 3641 def location @location end |
#value ⇒ Object (readonly)
- String
-
the contents of the comment
3633 3634 3635 |
# File 'lib/syntax_tree.rb', line 3633 def value @value end |
Instance Method Details
#comments ⇒ Object
3668 3669 3670 |
# File 'lib/syntax_tree.rb', line 3668 def comments [] end |
#format(q) ⇒ Object
3672 3673 3674 |
# File 'lib/syntax_tree.rb', line 3672 def format(q) q.text(value) end |
#leading! ⇒ Object
3652 3653 3654 |
# File 'lib/syntax_tree.rb', line 3652 def leading! @leading = true end |
#leading? ⇒ Boolean
3656 3657 3658 |
# File 'lib/syntax_tree.rb', line 3656 def leading? @leading end |
#pretty_print(q) ⇒ Object
3676 3677 3678 3679 3680 3681 3682 3683 |
# File 'lib/syntax_tree.rb', line 3676 def pretty_print(q) q.group(2, "(", ")") do q.text("comment") q.breakable q.pp(value) end end |
#to_json(*opts) ⇒ Object
3685 3686 3687 3688 3689 3690 3691 3692 |
# File 'lib/syntax_tree.rb', line 3685 def to_json(*opts) { type: :comment, value: value.force_encoding("UTF-8"), inline: inline, loc: location }.to_json(*opts) end |
#trailing! ⇒ Object
3660 3661 3662 |
# File 'lib/syntax_tree.rb', line 3660 def trailing! @trailing = true end |
#trailing? ⇒ Boolean
3664 3665 3666 |
# File 'lib/syntax_tree.rb', line 3664 def trailing? @trailing end |