123456789_123456789_123456789_123456789_123456789_

Class: Prism::Comment

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: lib/prism/parse_result.rb,
prism/extension.c

Overview

This represents a comment that was encountered during parsing. It is the base class for all comment types.

Class Method Summary

Instance Attribute Summary

  • #location readonly

    The Location of this comment in the source.

  • #trailing? ⇒ Boolean readonly

    Returns true if this comment happens on the same line as other code and false if the comment is by itself.

Instance Method Summary

  • #slice

    Returns the content of the comment by slicing it from the source code.

  • #deconstruct_keys(keys) Internal use only

    Implement the hash pattern matching interface for Comment.

Constructor Details

.new(location) ⇒ Comment

Create a new comment object with the given location.

[ GitHub ]

  
# File 'lib/prism/parse_result.rb', line 685

def initialize(location)
  @location = location
end

Instance Attribute Details

#location (readonly)

The Location of this comment in the source.

[ GitHub ]

  
# File 'lib/prism/parse_result.rb', line 680

attr_reader :location #: Location

#trailing?Boolean (readonly)

Returns true if this comment happens on the same line as other code and false if the comment is by itself. This can only be true for inline comments and should be false for block comments.

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'lib/prism/parse_result.rb', line 708

def trailing?
  raise NotImplementedError, "trailing? is not implemented for #{self.class}"
end

Instance Method Details

#deconstruct_keys(keys)

This method is for internal use only.

Implement the hash pattern matching interface for Comment.

[ GitHub ]

  
# File 'lib/prism/parse_result.rb', line 692

def deconstruct_keys(keys) # :nodoc:
  { location: location }
end

#slice

Returns the content of the comment by slicing it from the source code.

[ GitHub ]

  
# File 'lib/prism/parse_result.rb', line 699

def slice
  location.slice
end