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



4378
4379
4380
4381
4382
4383
# File 'lib/yarp/node.rb', line 4378

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?



4375
4376
4377
# File 'lib/yarp/node.rb', line 4375

def closing_loc
  @closing_loc
end

#opening_locObject (readonly)

attr_reader opening_loc: Location?



4369
4370
4371
# File 'lib/yarp/node.rb', line 4369

def opening_loc
  @opening_loc
end

#partsObject (readonly)

attr_reader parts: Array



4372
4373
4374
# File 'lib/yarp/node.rb', line 4372

def parts
  @parts
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



4386
4387
4388
# File 'lib/yarp/node.rb', line 4386

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

#child_nodesObject Also known as: deconstruct

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



4396
4397
4398
# File 'lib/yarp/node.rb', line 4396

def child_nodes
  [*parts]
end

#closingObject

def closing: () -> String?



4424
4425
4426
# File 'lib/yarp/node.rb', line 4424

def closing
  closing_loc&.slice
end

#copy(**params) ⇒ Object

def copy: (**params) -> InterpolatedStringNode



4401
4402
4403
4404
4405
4406
4407
4408
# File 'lib/yarp/node.rb', line 4401

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]



4414
4415
4416
# File 'lib/yarp/node.rb', line 4414

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

#openingObject

def opening: () -> String?



4419
4420
4421
# File 'lib/yarp/node.rb', line 4419

def opening
  opening_loc&.slice
end

#set_newline_flag(newline_marked) ⇒ Object



4390
4391
4392
4393
# File 'lib/yarp/node.rb', line 4390

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