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

#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.end_offset
end

#leading_comment(comment) ⇒ Object



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

def leading_comment(comment)
  node.location.leading_comment(comment)
end

#start_offsetObject



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

def start_offset
  node.start_offset
end

#trailing_comment(comment) ⇒ Object



46
47
48
# File 'lib/prism/parse_result/comments.rb', line 46

def trailing_comment(comment)
  node.location.trailing_comment(comment)
end