Class: Prism::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/prism/parse_result.rb,
ext/prism/extension.c

Overview

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

Direct Known Subclasses

EmbDocComment, InlineComment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ Comment

Create a new comment object with the given location.



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

def initialize(location)
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

The location of this comment in the source.



509
510
511
# File 'lib/prism/parse_result.rb', line 509

def location
  @location
end

Instance Method Details

#deconstruct_keys(keys) ⇒ Object

Implement the hash pattern matching interface for Comment.



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

def deconstruct_keys(keys)
  { location: location }
end

#sliceObject

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



522
523
524
# File 'lib/prism/parse_result.rb', line 522

def slice
  location.slice
end