Class: RuboCop::AST::NodePattern::Comment
- Inherits:
-
Object
- Object
- RuboCop::AST::NodePattern::Comment
- Defined in:
- lib/rubocop/ast/node_pattern/comment.rb
Overview
A NodePattern comment, simplified version of ::Parser::Source::Comment
Instance Attribute Summary collapse
-
#location ⇒ Object
(also: #loc)
readonly
Returns the value of attribute location.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares comments.
-
#initialize(range) ⇒ Comment
constructor
A new instance of Comment.
-
#inspect ⇒ String
A human-readable representation of this comment.
- #text ⇒ String
Constructor Details
#initialize(range) ⇒ Comment
Returns a new instance of Comment.
14 15 16 17 |
# File 'lib/rubocop/ast/node_pattern/comment.rb', line 14 def initialize(range) @location = ::Parser::Source::Map.new(range) freeze end |
Instance Attribute Details
#location ⇒ Object (readonly) Also known as: loc
Returns the value of attribute location.
8 9 10 |
# File 'lib/rubocop/ast/node_pattern/comment.rb', line 8 def location @location end |
Instance Method Details
#==(other) ⇒ Boolean
Compares comments. Two comments are equal if they correspond to the same source range.
31 32 33 34 |
# File 'lib/rubocop/ast/node_pattern/comment.rb', line 31 def ==(other) other.is_a?(Comment) && @location == other.location end |
#inspect ⇒ String
Returns a human-readable representation of this comment.
39 40 41 |
# File 'lib/rubocop/ast/node_pattern/comment.rb', line 39 def inspect "#<NodePattern::Comment #{@location.expression} #{text.inspect}>" end |
#text ⇒ String
20 21 22 |
# File 'lib/rubocop/ast/node_pattern/comment.rb', line 20 def text loc.expression.source.freeze end |