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
- #child_nodes ⇒ Object
- #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.
4059 4060 4061 4062 4063 4064 4065 4066 |
# File 'lib/syntax_tree.rb', line 4059 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.
4053 4054 4055 |
# File 'lib/syntax_tree.rb', line 4053 def inline @inline end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4057 4058 4059 |
# File 'lib/syntax_tree.rb', line 4057 def location @location end |
#value ⇒ Object (readonly)
- String
-
the contents of the comment
4049 4050 4051 |
# File 'lib/syntax_tree.rb', line 4049 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
4092 4093 4094 |
# File 'lib/syntax_tree.rb', line 4092 def child_nodes [] end |
#comments ⇒ Object
4088 4089 4090 |
# File 'lib/syntax_tree.rb', line 4088 def comments [] end |
#format(q) ⇒ Object
4096 4097 4098 |
# File 'lib/syntax_tree.rb', line 4096 def format(q) q.text(value) end |
#ignore? ⇒ Boolean
4084 4085 4086 |
# File 'lib/syntax_tree.rb', line 4084 def ignore? value[1..-1].strip == "stree-ignore" end |
#leading! ⇒ Object
4068 4069 4070 |
# File 'lib/syntax_tree.rb', line 4068 def leading! @leading = true end |
#leading? ⇒ Boolean
4072 4073 4074 |
# File 'lib/syntax_tree.rb', line 4072 def leading? @leading end |
#pretty_print(q) ⇒ Object
4100 4101 4102 4103 4104 4105 4106 4107 |
# File 'lib/syntax_tree.rb', line 4100 def pretty_print(q) q.group(2, "(", ")") do q.text("comment") q.breakable q.pp(value) end end |
#to_json(*opts) ⇒ Object
4109 4110 4111 4112 4113 4114 4115 4116 |
# File 'lib/syntax_tree.rb', line 4109 def to_json(*opts) { type: :comment, value: value.force_encoding("UTF-8"), inline: inline, loc: location }.to_json(*opts) end |
#trailing! ⇒ Object
4076 4077 4078 |
# File 'lib/syntax_tree.rb', line 4076 def trailing! @trailing = true end |
#trailing? ⇒ Boolean
4080 4081 4082 |
# File 'lib/syntax_tree.rb', line 4080 def trailing? @trailing end |