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.



5944
5945
5946
5947
5948
# File 'lib/syntax_tree/node.rb', line 5944

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5942
5943
5944
# File 'lib/syntax_tree/node.rb', line 5942

def comments
  @comments
end

#valueObject (readonly)

String

the closing declaration of the heredoc



5939
5940
5941
# File 'lib/syntax_tree/node.rb', line 5939

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5979
5980
5981
# File 'lib/syntax_tree/node.rb', line 5979

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

#accept(visitor) ⇒ Object



5950
5951
5952
# File 'lib/syntax_tree/node.rb', line 5950

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

#child_nodesObject Also known as: deconstruct



5954
5955
5956
# File 'lib/syntax_tree/node.rb', line 5954

def child_nodes
  []
end

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



5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
# File 'lib/syntax_tree/node.rb', line 5958

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



5971
5972
5973
# File 'lib/syntax_tree/node.rb', line 5971

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

#format(q) ⇒ Object



5975
5976
5977
# File 'lib/syntax_tree/node.rb', line 5975

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