Class: SyntaxTree::Comment
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::Comment
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
Comment represents a comment in the source.
Instance Attribute Summary collapse
-
#inline ⇒ Object
(also: #inline?)
readonly
- boolean
-
whether or not there is code on the same line as this comment.
-
#value ⇒ Object
readonly
- String
-
the contents of the comment.
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(value:, inline:, location:) ⇒ Comment
Returns a new instance of Comment.
3653
3654
3655
3656
3657
3658
3659
3660
|
# File 'lib/syntax_tree/node.rb', line 3653
def initialize(value:, inline:, location:)
@value = value
@inline = inline
@location = location
@leading = false
@trailing = false
end
|
Instance Attribute Details
#inline ⇒ Object
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.
3650
3651
3652
|
# File 'lib/syntax_tree/node.rb', line 3650
def inline
@inline
end
|
#value ⇒ Object
- String
-
the contents of the comment
3646
3647
3648
|
# File 'lib/syntax_tree/node.rb', line 3646
def value
@value
end
|
Instance Method Details
#===(other) ⇒ Object
3712
3713
3714
|
# File 'lib/syntax_tree/node.rb', line 3712
def ===(other)
other.is_a?(Comment) && value === other.value && inline === other.inline
end
|
#accept(visitor) ⇒ Object
3686
3687
3688
|
# File 'lib/syntax_tree/node.rb', line 3686
def accept(visitor)
visitor.(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
3690
3691
3692
|
# File 'lib/syntax_tree/node.rb', line 3690
def child_nodes
[]
end
|
3682
3683
3684
|
# File 'lib/syntax_tree/node.rb', line 3682
def
[]
end
|
#copy(value: nil, inline: nil, location: nil) ⇒ Object
3694
3695
3696
3697
3698
3699
3700
|
# File 'lib/syntax_tree/node.rb', line 3694
def copy(value: nil, inline: nil, location: nil)
Comment.new(
value: value || self.value,
inline: inline || self.inline,
location: location || self.location
)
end
|
#deconstruct_keys(_keys) ⇒ Object
3704
3705
3706
|
# File 'lib/syntax_tree/node.rb', line 3704
def deconstruct_keys(_keys)
{ value: value, inline: inline, location: location }
end
|
3708
3709
3710
|
# File 'lib/syntax_tree/node.rb', line 3708
def format(q)
q.text(value)
end
|
#ignore? ⇒ Boolean
3678
3679
3680
|
# File 'lib/syntax_tree/node.rb', line 3678
def ignore?
value.match?(/\A#\s*stree-ignore\s*\z/)
end
|
#leading! ⇒ Object
3662
3663
3664
|
# File 'lib/syntax_tree/node.rb', line 3662
def leading!
@leading = true
end
|
#leading? ⇒ Boolean
3666
3667
3668
|
# File 'lib/syntax_tree/node.rb', line 3666
def leading?
@leading
end
|
#trailing! ⇒ Object
3670
3671
3672
|
# File 'lib/syntax_tree/node.rb', line 3670
def trailing!
@trailing = true
end
|
#trailing? ⇒ Boolean
3674
3675
3676
|
# File 'lib/syntax_tree/node.rb', line 3674
def trailing?
@trailing
end
|