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.

Instance Method Summary

  • #deconstruct_keys(keys)

    Implement the hash pattern matching interface for Comment.

  • #slice

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

Constructor Details

.new(location) ⇒ Comment

Create a new comment object with the given location.

[ GitHub ]

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

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 509

attr_reader :location

Instance Method Details

#deconstruct_keys(keys)

Implement the hash pattern matching interface for Comment.

[ GitHub ]

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

def deconstruct_keys(keys)
  { 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 522

def slice
  location.slice
end