123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::AST::NodePattern::Comment

Relationships & Source Files
Inherits: Object
Defined in: lib/rubocop/ast/node_pattern/comment.rb

Overview

A NodePattern comment, simplified version of ::Parser::Source::Comment

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(range) ⇒ Comment

Parameters:

  • range (Parser::Source::Range)
[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/comment.rb', line 14

def initialize(range)
  @location = ::Parser::Source::Map.new(range)
  freeze
end

Instance Attribute Details

#loc (readonly)

Alias for #location.

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/comment.rb', line 9

alias loc location

#location (readonly) Also known as: #loc

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/comment.rb', line 8

attr_reader :location

Instance Method Details

#==(other) ⇒ Boolean

Compares comments. Two comments are equal if they correspond to the same source range.

Parameters:

  • other (Object)
[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/comment.rb', line 31

def ==(other)
  other.is_a?(Comment) &&
    @location == other.location
end

#inspectString

Returns:

  • (String)

    a human-readable representation of this comment

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/comment.rb', line 39

def inspect
  "#<NodePattern::Comment #{@location.expression} #{text.inspect}>"
end

#textString

[ GitHub ]

  
# File 'lib/rubocop/ast/node_pattern/comment.rb', line 20

def text
  loc.expression.source.freeze
end