class RuboCop::AST::StrNode

its methods available to all ‘str` nodes within RuboCop.
in place of a plain node when the builder constructs the AST, making
A node extension for `str`, `dstr`, and `xstr` nodes. This will be used

def character_literal?

def character_literal?
  loc_is?(:begin, '?')
end

def double_quoted?

def double_quoted?
  loc_is?(:begin, '"')
end

def heredoc?

def heredoc?
  loc.is_a?(Parser::Source::Map::Heredoc)
end

def percent_literal?(type = nil)

Returns:
  • (Boolean) - whether the string is enclosed in percent brackets

Parameters:
  • type (Symbol) -- an optional percent literal type

Overloads:
  • percent_literal?(type)
  • percent_literal?
def percent_literal?(type = nil)
  opening_delimiter = loc.begin if loc.respond_to?(:begin)
  return false unless opening_delimiter
  if type
    opening_delimiter.source.match?(PERCENT_LITERAL_TYPES.fetch(type))
  else
    opening_delimiter.source.start_with?('%')
  end
end

def single_quoted?

def single_quoted?
  loc_is?(:begin, "'")
end