123456789_123456789_123456789_123456789_123456789_

Class: Prism::MagicComment

Relationships & Source Files
Inherits: Object
Defined in: lib/prism/parse_result.rb,
prism/extension.c

Overview

This represents a magic comment that was encountered during parsing.

Class Method Summary

Instance Attribute Summary

  • #key_loc readonly

    A Location object representing the location of the key in the source.

  • #value_loc readonly

    A Location object representing the location of the value in the source.

Instance Method Summary

  • #deconstruct_keys(keys)

    Implement the hash pattern matching interface for MagicComment.

  • #inspect

    Returns a string representation of this magic comment.

  • #key

    Returns the key of the magic comment by slicing it from the source code.

  • #value

    Returns the value of the magic comment by slicing it from the source code.

Constructor Details

.new(key_loc, value_loc) ⇒ MagicComment

Create a new magic comment object with the given key and value locations.

[ GitHub ]

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

def initialize(key_loc, value_loc)
  @key_loc = key_loc
  @value_loc = value_loc
end

Instance Attribute Details

#key_loc (readonly)

A Location object representing the location of the key in the source.

[ GitHub ]

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

attr_reader :key_loc

#value_loc (readonly)

A Location object representing the location of the value in the source.

[ GitHub ]

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

attr_reader :value_loc

Instance Method Details

#deconstruct_keys(keys)

Implement the hash pattern matching interface for MagicComment.

[ GitHub ]

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

def deconstruct_keys(keys)
  { key_loc: key_loc, value_loc: value_loc }
end

#inspect

Returns a string representation of this magic comment.

[ GitHub ]

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

def inspect
  "#<Prism::MagicComment @key=#{key.inspect} @value=#{value.inspect}>"
end

#key

Returns the key of the magic comment by slicing it from the source code.

[ GitHub ]

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

def key
  key_loc.slice
end

#value

Returns the value of the magic comment by slicing it from the source code.

[ GitHub ]

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

def value
  value_loc.slice
end