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.
3938 3939 3940 3941 3942 3943 3944 3945 |
# File 'lib/syntax_tree.rb', line 3938 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.
3932 3933 3934 |
# File 'lib/syntax_tree.rb', line 3932 def inline @inline end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
3936 3937 3938 |
# File 'lib/syntax_tree.rb', line 3936 def location @location end |
#value ⇒ Object (readonly)
- String
-
the contents of the comment
3928 3929 3930 |
# File 'lib/syntax_tree.rb', line 3928 def value @value end |
Instance Method Details
#comments ⇒ Object
3967 3968 3969 |
# File 'lib/syntax_tree.rb', line 3967 def comments [] end |
#format(q) ⇒ Object
3971 3972 3973 |
# File 'lib/syntax_tree.rb', line 3971 def format(q) q.text(value) end |
#ignore? ⇒ Boolean
3963 3964 3965 |
# File 'lib/syntax_tree.rb', line 3963 def ignore? value[1..-1].strip == "stree-ignore" end |
#leading! ⇒ Object
3947 3948 3949 |
# File 'lib/syntax_tree.rb', line 3947 def leading! @leading = true end |
#leading? ⇒ Boolean
3951 3952 3953 |
# File 'lib/syntax_tree.rb', line 3951 def leading? @leading end |
#pretty_print(q) ⇒ Object
3975 3976 3977 3978 3979 3980 3981 3982 |
# File 'lib/syntax_tree.rb', line 3975 def pretty_print(q) q.group(2, "(", ")") do q.text("comment") q.breakable q.pp(value) end end |
#to_json(*opts) ⇒ Object
3984 3985 3986 3987 3988 3989 3990 3991 |
# File 'lib/syntax_tree.rb', line 3984 def to_json(*opts) { type: :comment, value: value.force_encoding("UTF-8"), inline: inline, loc: location }.to_json(*opts) end |
#trailing! ⇒ Object
3955 3956 3957 |
# File 'lib/syntax_tree.rb', line 3955 def trailing! @trailing = true end |
#trailing? ⇒ Boolean
3959 3960 3961 |
# File 'lib/syntax_tree.rb', line 3959 def trailing? @trailing end |