class Prism::Comment - Documentation for Ruby 4.1
Description: class Prism::Comment: This represents a comment that was encountered during parsing. It is the base class for all comment types.
Keywords: ruby,class,Prism::Comment

🔍

No recent searches

# class Prism::Comment

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

### Attributes

location [R]

The `Location` of this comment in the source.

### Public Class Methods

new (location)
Source

    # File lib/prism/parse_result.rb, line 710
    def initialize(location)
      @location = location
    end

Create a new comment object with the given location.

### Public Instance Methods

slice ()
Source

    # File lib/prism/parse_result.rb, line 724
    def slice
      location.slice
    end

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

trailing? ()
Source

    # File lib/prism/parse_result.rb, line 733
    def trailing?
      raise NotImplementedError, "trailing? is not implemented for #{self.class}"
    end

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.