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

Constructor Details

#initialize(value:, location:) ⇒ HeredocBeg

Returns a new instance of HeredocBeg.



5794
5795
5796
5797
5798
# File 'lib/syntax_tree/node.rb', line 5794

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5792
5793
5794
# File 'lib/syntax_tree/node.rb', line 5792

def comments
  @comments
end

#valueObject (readonly)

String

the opening declaration of the heredoc



5789
5790
5791
# File 'lib/syntax_tree/node.rb', line 5789

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



5800
5801
5802
# File 'lib/syntax_tree/node.rb', line 5800

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

#child_nodesObject Also known as: deconstruct



5804
5805
5806
# File 'lib/syntax_tree/node.rb', line 5804

def child_nodes
  []
end

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



5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
# File 'lib/syntax_tree/node.rb', line 5808

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



5821
5822
5823
# File 'lib/syntax_tree/node.rb', line 5821

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

#format(q) ⇒ Object



5825
5826
5827
# File 'lib/syntax_tree/node.rb', line 5825

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