Class: SyntaxTree::HeredocBeg

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

Overview

HeredocBeg represents the beginning declaration of a heredoc.

"contents\n"

In the example above the HeredocBeg node represents <<~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:) ⇒ HeredocBeg

Returns a new instance of HeredocBeg.



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5838
5839
5840
# File 'lib/syntax_tree/node.rb', line 5838

def comments
  @comments
end

#valueObject (readonly)

String

the opening declaration of the heredoc



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

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5875
5876
5877
# File 'lib/syntax_tree/node.rb', line 5875

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

#accept(visitor) ⇒ Object



5846
5847
5848
# File 'lib/syntax_tree/node.rb', line 5846

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

#child_nodesObject Also known as: deconstruct



5850
5851
5852
# File 'lib/syntax_tree/node.rb', line 5850

def child_nodes
  []
end

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



5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
# File 'lib/syntax_tree/node.rb', line 5854

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

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

#deconstruct_keys(_keys) ⇒ Object



5867
5868
5869
# File 'lib/syntax_tree/node.rb', line 5867

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

#format(q) ⇒ Object



5871
5872
5873
# File 'lib/syntax_tree/node.rb', line 5871

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