Class: RuboCop::StringInterpreter

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/string_interpreter.rb

Overview

Take a string with embedded escapes, and convert the escapes as the Ruby interpreter would when reading a double-quoted string literal. For example, ā€œ\nā€ will be converted to ā€œnā€.

Class Method Summary collapse

Class Method Details

.interpret(string) ⇒ Object



24
25
26
27
28
29
# File 'lib/rubocop/string_interpreter.rb', line 24

def interpret(string)
  # We currently don't handle \cx, \C-x, and \M-x
  string.gsub(STRING_ESCAPE_REGEX) do |escape|
    STRING_ESCAPES[escape] || interpret_string_escape(escape)
  end
end