Class: SyntaxTree::HeredocBeg

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

Overview

HeredocBeg represents the beginning declaration of a heredoc.

<<~DOC
  contents
DOC

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.



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



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

def comments
  @comments
end

#valueObject (readonly)

String

the opening declaration of the heredoc



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

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

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



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

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



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

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

#format(q) ⇒ Object



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

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