Class: Prism::MagicComment
- Inherits:
-
Object
- Object
- Prism::MagicComment
- Defined in:
- lib/prism/parse_result.rb,
ext/prism/extension.c
Overview
This represents a magic comment that was encountered during parsing.
Instance Attribute Summary collapse
-
#key_loc ⇒ Object
readonly
A Location object representing the location of the key in the source.
-
#value_loc ⇒ Object
readonly
A Location object representing the location of the value in the source.
Instance Method Summary collapse
-
#deconstruct_keys(keys) ⇒ Object
Implement the hash pattern matching interface for MagicComment.
-
#initialize(key_loc, value_loc) ⇒ MagicComment
constructor
Create a new magic comment object with the given key and value locations.
-
#inspect ⇒ Object
Returns a string representation of this magic comment.
-
#key ⇒ Object
Returns the key of the magic comment by slicing it from the source code.
-
#value ⇒ Object
Returns the value of the magic comment by slicing it from the source code.
Constructor Details
#initialize(key_loc, value_loc) ⇒ MagicComment
Create a new magic comment object with the given key and value locations.
583 584 585 586 |
# File 'lib/prism/parse_result.rb', line 583 def initialize(key_loc, value_loc) @key_loc = key_loc @value_loc = value_loc end |
Instance Attribute Details
#key_loc ⇒ Object (readonly)
A Location object representing the location of the key in the source.
577 578 579 |
# File 'lib/prism/parse_result.rb', line 577 def key_loc @key_loc end |
#value_loc ⇒ Object (readonly)
A Location object representing the location of the value in the source.
580 581 582 |
# File 'lib/prism/parse_result.rb', line 580 def value_loc @value_loc end |
Instance Method Details
#deconstruct_keys(keys) ⇒ Object
Implement the hash pattern matching interface for MagicComment.
599 600 601 |
# File 'lib/prism/parse_result.rb', line 599 def deconstruct_keys(keys) { key_loc: key_loc, value_loc: value_loc } end |
#inspect ⇒ Object
Returns a string representation of this magic comment.
604 605 606 |
# File 'lib/prism/parse_result.rb', line 604 def inspect "#<Prism::MagicComment @key=#{key.inspect} @value=#{value.inspect}>" end |
#key ⇒ Object
Returns the key of the magic comment by slicing it from the source code.
589 590 591 |
# File 'lib/prism/parse_result.rb', line 589 def key key_loc.slice end |
#value ⇒ Object
Returns the value of the magic comment by slicing it from the source code.
594 595 596 |
# File 'lib/prism/parse_result.rb', line 594 def value value_loc.slice end |