Class: Prism::ParseResult::Comments::NodeTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/prism/parse_result/comments.rb

Overview

A target for attaching comments that is based on a specific node’s location.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ NodeTarget

Returns a new instance of NodeTarget.



25
26
27
# File 'lib/prism/parse_result/comments.rb', line 25

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

:nodoc:



23
24
25
# File 'lib/prism/parse_result/comments.rb', line 23

def node
  @node
end

Instance Method Details

#<<(comment) ⇒ Object



42
43
44
# File 'lib/prism/parse_result/comments.rb', line 42

def <<(comment)
  node.location.comments << comment
end

#encloses?(comment) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/prism/parse_result/comments.rb', line 37

def encloses?(comment)
  start_offset <= comment.location.start_offset &&
    comment.location.end_offset <= end_offset
end

#end_offsetObject



33
34
35
# File 'lib/prism/parse_result/comments.rb', line 33

def end_offset
  node.location.end_offset
end

#start_offsetObject



29
30
31
# File 'lib/prism/parse_result/comments.rb', line 29

def start_offset
  node.location.start_offset
end