Class: SyntaxTree::HeredocEnd

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

Overview

HeredocEnd represents the closing declaration of a heredoc.

"contents\n"

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, #pretty_print, #to_json

Constructor Details

#initialize(value:, location:) ⇒ HeredocEnd



5834
5835
5836
5837
5838
# File 'lib/syntax_tree/node.rb', line 5834

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5832
5833
5834
# File 'lib/syntax_tree/node.rb', line 5832

def comments
  @comments
end

#valueObject (readonly)

String

the closing declaration of the heredoc



5829
5830
5831
# File 'lib/syntax_tree/node.rb', line 5829

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5869
5870
5871
# File 'lib/syntax_tree/node.rb', line 5869

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

#accept(visitor) ⇒ Object



5840
5841
5842
# File 'lib/syntax_tree/node.rb', line 5840

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

#child_nodesObject Also known as: deconstruct



5844
5845
5846
# File 'lib/syntax_tree/node.rb', line 5844

def child_nodes
  []
end

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



5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
# File 'lib/syntax_tree/node.rb', line 5848

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



5861
5862
5863
# File 'lib/syntax_tree/node.rb', line 5861

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

#format(q) ⇒ Object



5865
5866
5867
# File 'lib/syntax_tree/node.rb', line 5865

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