Class: Prism::InterpolatedXStringNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
lib/prism/node_ext.rb,
lib/prism/parse_result/newlines.rb,
ext/prism/api_node.c

Overview

Represents an xstring literal that contains interpolation.

`foo #{bar} baz`
^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, opening_loc, parts, closing_loc) ⇒ InterpolatedXStringNode

Initialize a new InterpolatedXStringNode node.



9873
9874
9875
9876
9877
9878
9879
9880
9881
# File 'lib/prism/node.rb', line 9873

def initialize(source, node_id, location, flags, opening_loc, parts, closing_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @opening_loc = opening_loc
  @parts = parts
  @closing_loc = closing_loc
end

Instance Attribute Details

#partsObject (readonly)

attr_reader parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode]



9924
9925
9926
# File 'lib/prism/node.rb', line 9924

def parts
  @parts
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



9954
9955
9956
# File 'lib/prism/node.rb', line 9954

def self.type
  :interpolated_x_string_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



9960
9961
9962
9963
9964
9965
9966
# File 'lib/prism/node.rb', line 9960

def ===(other)
  other.is_a?(InterpolatedXStringNode) &&
    (opening_loc.nil? == other.opening_loc.nil?) &&
    (parts.length == other.parts.length) &&
    parts.zip(other.parts).all? { |left, right| left === right } &&
    (closing_loc.nil? == other.closing_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



9884
9885
9886
# File 'lib/prism/node.rb', line 9884

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



9889
9890
9891
# File 'lib/prism/node.rb', line 9889

def child_nodes
  [*parts]
end

#closingObject

def closing: () -> String



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

def closing
  closing_loc.slice
end

#closing_locObject

attr_reader closing_loc: Location



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

def closing_loc
  location = @closing_loc
  return location if location.is_a?(Location)
  @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



9899
9900
9901
# File 'lib/prism/node.rb', line 9899

def comment_targets
  [opening_loc, *parts, closing_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



9894
9895
9896
# File 'lib/prism/node.rb', line 9894

def compact_child_nodes
  [*parts]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, parts: self.parts, closing_loc: self.closing_loc) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], ?closing_loc: Location) -> InterpolatedXStringNode



9904
9905
9906
# File 'lib/prism/node.rb', line 9904

def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, parts: self.parts, closing_loc: self.closing_loc)
  InterpolatedXStringNode.new(source, node_id, location, flags, opening_loc, parts, closing_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, opening_loc: Location, parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], closing_loc: Location }



9912
9913
9914
# File 'lib/prism/node.rb', line 9912

def deconstruct_keys(keys)
  { node_id: node_id, location: location, opening_loc: opening_loc, parts: parts, closing_loc: closing_loc }
end

#inspectObject

def inspect -> String



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

def inspect
  InspectVisitor.compose(self)
end

#newline_flag!(lines) ⇒ Object

:nodoc:



149
150
151
152
# File 'lib/prism/parse_result/newlines.rb', line 149

def newline_flag!(lines) # :nodoc:
  first = parts.first
  first.newline_flag!(lines) if first
end

#openingObject

def opening: () -> String



9934
9935
9936
# File 'lib/prism/node.rb', line 9934

def opening
  opening_loc.slice
end

#opening_locObject

attr_reader opening_loc: Location



9917
9918
9919
9920
9921
# File 'lib/prism/node.rb', line 9917

def opening_loc
  location = @opening_loc
  return location if location.is_a?(Location)
  @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



9949
9950
9951
# File 'lib/prism/node.rb', line 9949

def type
  :interpolated_x_string_node
end