1. Prism::
  2. StringNode

class Prism::StringNode

Represents a string literal, a string contained within a%w list, or plain string content within an interpolated string.

"foo"^^^^^%w[foo]   ^^^"foo #{bar} baz" ^^^^      ^^^^

Attributes

unescaped[R]

attr_reader unescaped:String

Public Class Methods

Source
# File lib/prism/node.rb, line 17081definitialize(source,node_id,location,flags,opening_loc,content_loc,closing_loc,unescaped)@source =source@node_id =node_id@location =location@flags =flags@opening_loc =opening_loc@content_loc =content_loc@closing_loc =closing_loc@unescaped =unescapedend

Initialize a newStringNode node.

Source
# File lib/prism/node.rb, line 17225defself.type:string_nodeend

Return a symbol representation of this node type. SeeNode::type.

Public Instance Methods

Source
# File lib/prism/node.rb, line 17231def===(other)other.is_a?(StringNode)&&    (flags===other.flags)&&    (opening_loc.nil?==other.opening_loc.nil?)&&    (content_loc.nil?==other.content_loc.nil?)&&    (closing_loc.nil?==other.closing_loc.nil?)&&    (unescaped===other.unescaped)end

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

Source
# File lib/prism/node.rb, line 17093defaccept(visitor)visitor.visit_string_node(self)end

def accept: (Visitor visitor) -> void

Source
# File lib/prism/node.rb, line 17098defchild_nodes  []end

defchild_nodes: () ->Array

Also aliased as:deconstruct
Source
# File lib/prism/node.rb, line 17210defclosingclosing_loc&.sliceend

def closing: () ->String?

Source
# File lib/prism/node.rb, line 17178defclosing_loclocation =@closing_loccaselocationwhennilnilwhenLocationlocationelse@closing_loc =Location.new(source,location>>32,location&0xFFFFFFFF)endend

attr_readerclosing_loc:Location?

Source
# File lib/prism/node.rb, line 17108defcomment_targets  [*opening_loc,content_loc,*closing_loc]#: Array[Prism::node | Location]end

defcomment_targets: () -> Array[Node | Location]

Source
# File lib/prism/node.rb, line 17103defcompact_child_nodes  []end

defcompact_child_nodes: () ->Array

Source
# File lib/prism/node.rb, line 17205defcontentcontent_loc.sliceend

def content: () ->String

Source
# File lib/prism/node.rb, line 17165defcontent_loclocation =@content_locreturnlocationiflocation.is_a?(Location)@content_loc =Location.new(source,location>>32,location&0xFFFFFFFF)end

attr_readercontent_loc:Location

Source
# File lib/prism/node.rb, line 17113defcopy(node_id:self.node_id,location:self.location,flags:self.flags,opening_loc:self.opening_loc,content_loc:self.content_loc,closing_loc:self.closing_loc,unescaped:self.unescaped)StringNode.new(source,node_id,location,flags,opening_loc,content_loc,closing_loc,unescaped)end

def copy: (?node_id:Integer, ?location:Location, ?flags:Integer, ?opening_loc:Location?, ?content_loc:Location, ?closing_loc:Location?, ?unescaped:String) ->StringNode

def deconstruct: () ->Array

Alias for:child_nodes
Source
# File lib/prism/node.rb, line 17121defdeconstruct_keys(keys)  {node_id:node_id,location:location,opening_loc:opening_loc,content_loc:content_loc,closing_loc:closing_loc,unescaped:unescaped }end

defdeconstruct_keys: (Array keys) -> { node_id:Integer, location:Location,opening_loc:Location?,content_loc:Location,closing_loc:Location?, unescaped:String }

Source
# File lib/prism/node.rb, line 17131defforced_binary_encoding?flags.anybits?(StringFlags::FORCED_BINARY_ENCODING)end

def forced_binary_encoding?: () -> bool

Source
# File lib/prism/node.rb, line 17126defforced_utf8_encoding?flags.anybits?(StringFlags::FORCED_UTF8_ENCODING)end

def forced_utf8_encoding?: () -> bool

Source
# File lib/prism/node.rb, line 17136deffrozen?flags.anybits?(StringFlags::FROZEN)end

def frozen?: () -> bool

Source
# File lib/prism/node.rb, line 17215definspectInspectVisitor.compose(self)end

def inspect ->String

Source
# File lib/prism/node.rb, line 17141defmutable?flags.anybits?(StringFlags::MUTABLE)end

def mutable?: () -> bool

Source
# File lib/prism/node.rb, line 17200defopeningopening_loc&.sliceend

def opening: () ->String?

Source
# File lib/prism/node.rb, line 17146defopening_loclocation =@opening_loccaselocationwhennilnilwhenLocationlocationelse@opening_loc =Location.new(source,location>>32,location&0xFFFFFFFF)endend

attr_readeropening_loc:Location?

Source
# File lib/prism/node.rb, line 17192defsave_closing_loc(repository)repository.enter(node_id,:closing_loc)unless@closing_loc.nil?end

Save theclosing_loc location using the given saved source so that it can be retrieved later.

Source
# File lib/prism/node.rb, line 17173defsave_content_loc(repository)repository.enter(node_id,:content_loc)end

Save thecontent_loc location using the given saved source so that it can be retrieved later.

Source
# File lib/prism/node.rb, line 17160defsave_opening_loc(repository)repository.enter(node_id,:opening_loc)unless@opening_loc.nil?end

Save theopening_loc location using the given saved source so that it can be retrieved later.

Source
# File lib/prism/node_ext.rb, line 75defto_interpolatedInterpolatedStringNode.new(source,-1,location,frozen??InterpolatedStringNodeFlags::FROZEN:0,opening_loc,    [copy(location:content_loc,opening_loc:nil,closing_loc:nil)],closing_loc  )end

Occasionally it’s helpful to treat a string as if it were interpolated so that there’s a consistent interface for working with strings.

Source
# File lib/prism/node.rb, line 17220deftype:string_nodeend

Return a symbol representation of this node type. SeeNode#type.