Class: SyntaxTree::XStringLiteral

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

Overview

XStringLiteral represents a string that gets executed.

`ls`

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(parts:, location:, comments: []) ⇒ XStringLiteral

Returns a new instance of XStringLiteral.



9905
9906
9907
9908
9909
# File 'lib/syntax_tree/node.rb', line 9905

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9903
9904
9905
# File 'lib/syntax_tree/node.rb', line 9903

def comments
  @comments
end

#partsObject (readonly)

Array[ StringEmbExpr | StringDVar | TStringContent ]

the parts of the

xstring



9900
9901
9902
# File 'lib/syntax_tree/node.rb', line 9900

def parts
  @parts
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  parts
end

#deconstruct_keys(_keys) ⇒ Object



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

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

#format(q) ⇒ Object



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

def format(q)
  q.text("`")
  q.format_each(parts)
  q.text("`")
end