Class: SyntaxTree::HeredocEnd

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

HeredocEnd represents the closing declaration of a heredoc.

<<~DOC
  contents
DOC

In the example above the HeredocEnd node represents the closing DOC.

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(value:, location:) ⇒ HeredocEnd

Returns a new instance of HeredocEnd.



5894
5895
5896
5897
5898
# File 'lib/syntax_tree/node.rb', line 5894

def initialize(value:, location:)
  @value = value
  @location = location
  @comments = []
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5892
5893
5894
# File 'lib/syntax_tree/node.rb', line 5892

def comments
  @comments
end

#valueObject (readonly)

String

the closing declaration of the heredoc



5889
5890
5891
# File 'lib/syntax_tree/node.rb', line 5889

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5929
5930
5931
# File 'lib/syntax_tree/node.rb', line 5929

def ===(other)
  other.is_a?(HeredocEnd) && value === other.value
end

#accept(visitor) ⇒ Object



5900
5901
5902
# File 'lib/syntax_tree/node.rb', line 5900

def accept(visitor)
  visitor.visit_heredoc_end(self)
end

#child_nodesObject Also known as: deconstruct



5904
5905
5906
# File 'lib/syntax_tree/node.rb', line 5904

def child_nodes
  []
end

#copy(value: nil, location: nil) ⇒ Object



5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
# File 'lib/syntax_tree/node.rb', line 5908

def copy(value: nil, location: nil)
  node =
    HeredocEnd.new(
      value: value || self.value,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



5921
5922
5923
# File 'lib/syntax_tree/node.rb', line 5921

def deconstruct_keys(_keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



5925
5926
5927
# File 'lib/syntax_tree/node.rb', line 5925

def format(q)
  q.text(value)
end