Class: SyntaxTree::StringContent

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

Overview

StringContent represents the contents of a string-like value.

"string"

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #format, #pretty_print, #to_json

Constructor Details

#initialize(parts:, location:) ⇒ StringContent



9922
9923
9924
9925
# File 'lib/syntax_tree/node.rb', line 9922

def initialize(parts:, location:)
  @parts = parts
  @location = location
end

Instance Attribute Details

#partsObject (readonly)

Array[ StringEmbExpr | StringDVar | TStringContent ]

the parts of the

string



9920
9921
9922
# File 'lib/syntax_tree/node.rb', line 9920

def parts
  @parts
end

Instance Method Details

#===(other) ⇒ Object



9948
9949
9950
# File 'lib/syntax_tree/node.rb', line 9948

def ===(other)
  other.is_a?(StringContent) && ArrayMatch.call(parts, other.parts)
end

#accept(visitor) ⇒ Object



9927
9928
9929
# File 'lib/syntax_tree/node.rb', line 9927

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

#child_nodesObject Also known as: deconstruct



9931
9932
9933
# File 'lib/syntax_tree/node.rb', line 9931

def child_nodes
  parts
end

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



9935
9936
9937
9938
9939
9940
# File 'lib/syntax_tree/node.rb', line 9935

def copy(parts: nil, location: nil)
  StringContent.new(
    parts: parts || self.parts,
    location: location || self.location
  )
end

#deconstruct_keys(_keys) ⇒ Object



9944
9945
9946
# File 'lib/syntax_tree/node.rb', line 9944

def deconstruct_keys(_keys)
  { parts: parts, location: location }
end