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

Returns a new instance of StringContent.



9913
9914
9915
9916
# File 'lib/syntax_tree/node.rb', line 9913

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

Instance Attribute Details

#partsObject (readonly)

Array[ StringEmbExpr | StringDVar | TStringContent ]

the parts of the

string



9911
9912
9913
# File 'lib/syntax_tree/node.rb', line 9911

def parts
  @parts
end

Instance Method Details

#===(other) ⇒ Object



9939
9940
9941
# File 'lib/syntax_tree/node.rb', line 9939

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

#accept(visitor) ⇒ Object



9918
9919
9920
# File 'lib/syntax_tree/node.rb', line 9918

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  parts
end

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



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

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

#deconstruct_keys(_keys) ⇒ Object



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

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