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

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/ast/node_pattern/comment.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(range) ⇒ Comment

Returns a new instance of Comment.

Parameters:

  • range (Parser::Source::Range)


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

#locationObject (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.

Parameters:

  • other (Object)

Returns:

  • (Boolean)


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

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

#inspectString

Returns a human-readable representation of this comment.

Returns:

  • (String)

    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

#textString

Returns:

  • (String)


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

def text
  loc.expression.source.freeze
end