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
- #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.
3901 3902 3903 3904 3905 3906 3907 3908 |
# File 'lib/syntax_tree.rb', line 3901 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.
3895 3896 3897 |
# File 'lib/syntax_tree.rb', line 3895 def inline @inline end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
3899 3900 3901 |
# File 'lib/syntax_tree.rb', line 3899 def location @location end |
#value ⇒ Object (readonly)
- String
-
the contents of the comment
3891 3892 3893 |
# File 'lib/syntax_tree.rb', line 3891 def value @value end |
Instance Method Details
#comments ⇒ Object
3930 3931 3932 |
# File 'lib/syntax_tree.rb', line 3930 def comments [] end |
#format(q) ⇒ Object
3934 3935 3936 |
# File 'lib/syntax_tree.rb', line 3934 def format(q) q.text(value) end |
#ignore? ⇒ Boolean
3926 3927 3928 |
# File 'lib/syntax_tree.rb', line 3926 def ignore? value[1..-1].strip == "stree-ignore" end |
#leading! ⇒ Object
3910 3911 3912 |
# File 'lib/syntax_tree.rb', line 3910 def leading! @leading = true end |
#leading? ⇒ Boolean
3914 3915 3916 |
# File 'lib/syntax_tree.rb', line 3914 def leading? @leading end |
#pretty_print(q) ⇒ Object
3938 3939 3940 3941 3942 3943 3944 3945 |
# File 'lib/syntax_tree.rb', line 3938 def pretty_print(q) q.group(2, "(", ")") do q.text("comment") q.breakable q.pp(value) end end |
#to_json(*opts) ⇒ Object
3947 3948 3949 3950 3951 3952 3953 3954 |
# File 'lib/syntax_tree.rb', line 3947 def to_json(*opts) { type: :comment, value: value.force_encoding("UTF-8"), inline: inline, loc: location }.to_json(*opts) end |
#trailing! ⇒ Object
3918 3919 3920 |
# File 'lib/syntax_tree.rb', line 3918 def trailing! @trailing = true end |
#trailing? ⇒ Boolean
3922 3923 3924 |
# File 'lib/syntax_tree.rb', line 3922 def trailing? @trailing end |