Class: YARP::InterpolatedXStringNode

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

Overview

Represents an xstring literal that contains interpolation.

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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



6083
6084
6085
6086
6087
6088
# File 'lib/yarp/node.rb', line 6083

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



6080
6081
6082
# File 'lib/yarp/node.rb', line 6080

def closing_loc
  @closing_loc
end

#opening_locObject (readonly)

attr_reader opening_loc: Location



6074
6075
6076
# File 'lib/yarp/node.rb', line 6074

def opening_loc
  @opening_loc
end

#partsObject (readonly)

attr_reader parts: Array



6077
6078
6079
# File 'lib/yarp/node.rb', line 6077

def parts
  @parts
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



6091
6092
6093
# File 'lib/yarp/node.rb', line 6091

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

#child_nodesObject Also known as: deconstruct

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



6101
6102
6103
# File 'lib/yarp/node.rb', line 6101

def child_nodes
  [*parts]
end

#closingObject

def closing: () -> String



6134
6135
6136
# File 'lib/yarp/node.rb', line 6134

def closing
  closing_loc.slice
end

#comment_targetsObject

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



6106
6107
6108
# File 'lib/yarp/node.rb', line 6106

def comment_targets
  [opening_loc, *parts, closing_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> InterpolatedXStringNode



6111
6112
6113
6114
6115
6116
6117
6118
# File 'lib/yarp/node.rb', line 6111

def copy(**params)
  InterpolatedXStringNode.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]



6124
6125
6126
# File 'lib/yarp/node.rb', line 6124

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

#inspect(inspector = NodeInspector.new) ⇒ Object



6138
6139
6140
6141
6142
6143
6144
# File 'lib/yarp/node.rb', line 6138

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



6129
6130
6131
# File 'lib/yarp/node.rb', line 6129

def opening
  opening_loc.slice
end

#set_newline_flag(newline_marked) ⇒ Object



6095
6096
6097
6098
# File 'lib/yarp/node.rb', line 6095

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