Skip to Content Skip to Search

This represents a magic comment that was encountered during parsing.

Methods
D
I
K
N
V

Attributes

[R] key_loc

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

[R] value_loc

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

Class Public methods

new(key_loc, value_loc)

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

# File ruby/lib/prism/parse_result.rb, line 281
def initialize(key_loc, value_loc)
  @key_loc = key_loc
  @value_loc = value_loc
end

Instance Public methods

deconstruct_keys(keys)

Implement the hash pattern matching interface for MagicComment.

# File ruby/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.

# File ruby/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.

# File ruby/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.

# File ruby/lib/prism/parse_result.rb, line 292
def value
  value_loc.slice
end