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.



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

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

:nodoc:



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

def node
  @node
end

Instance Method Details

#encloses?(comment) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#end_offsetObject



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

def end_offset
  node.end_offset
end

#leading_comment(comment) ⇒ Object



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

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

#start_offsetObject



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

def start_offset
  node.start_offset
end

#trailing_comment(comment) ⇒ Object



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

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