Class: YARP::InterpolatedStringNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents a string literal that contains interpolation.

"foo #{bar} baz"
^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opening_loc, parts, closing_loc, location) ⇒ InterpolatedStringNode

def initialize: (opening_loc: Location?, parts: Array, closing_loc: Location?, location: Location) -> void



5925
5926
5927
5928
5929
5930
# File 'lib/yarp/node.rb', line 5925

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

Instance Attribute Details

#closing_locObject (readonly)

attr_reader closing_loc: Location?



5922
5923
5924
# File 'lib/yarp/node.rb', line 5922

def closing_loc
  @closing_loc
end

#opening_locObject (readonly)

attr_reader opening_loc: Location?



5916
5917
5918
# File 'lib/yarp/node.rb', line 5916

def opening_loc
  @opening_loc
end

#partsObject (readonly)

attr_reader parts: Array



5919
5920
5921
# File 'lib/yarp/node.rb', line 5919

def parts
  @parts
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



5933
5934
5935
# File 'lib/yarp/node.rb', line 5933

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

#child_nodesObject Also known as: deconstruct

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



5943
5944
5945
# File 'lib/yarp/node.rb', line 5943

def child_nodes
  [*parts]
end

#closingObject

def closing: () -> String?



5976
5977
5978
# File 'lib/yarp/node.rb', line 5976

def closing
  closing_loc&.slice
end

#comment_targetsObject

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



5948
5949
5950
# File 'lib/yarp/node.rb', line 5948

def comment_targets
  [*opening_loc, *parts, *closing_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> InterpolatedStringNode



5953
5954
5955
5956
5957
5958
5959
5960
# File 'lib/yarp/node.rb', line 5953

def copy(**params)
  InterpolatedStringNode.new(
    params.fetch(:opening_loc) { opening_loc },
    params.fetch(:parts) { parts },
    params.fetch(:closing_loc) { closing_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



5966
5967
5968
# File 'lib/yarp/node.rb', line 5966

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

#inspect(inspector = NodeInspector.new) ⇒ Object



5980
5981
5982
5983
5984
5985
5986
# File 'lib/yarp/node.rb', line 5980

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n"
  inspector << "├── parts: #{inspector.list("#{inspector.prefix}", parts)}"
  inspector << "└── closing_loc: #{inspector.location(closing_loc)}\n"
  inspector.to_str
end

#openingObject

def opening: () -> String?



5971
5972
5973
# File 'lib/yarp/node.rb', line 5971

def opening
  opening_loc&.slice
end

#set_newline_flag(newline_marked) ⇒ Object



5937
5938
5939
5940
# File 'lib/yarp/node.rb', line 5937

def set_newline_flag(newline_marked)
  first = parts.first
  first.set_newline_flag(newline_marked) if first
end