Skip to main content

ruby_escape_str

Function ruby_escape_str 

Source
pub fn ruby_escape_str(s: &str) -> String
Expand description

Escape a string for safe inclusion inside a double-quoted Ruby string literal: replace \ with \\ first, then " with \".

Backslash must be escaped before the quote so the quote’s inserted escape backslash is not itself doubled. Use this anywhere a user-supplied value is spliced into a "…" Ruby literal — both the Tera ruby_escape filter (registered by register_ruby_escape) and the format!/push_str sites in the Homebrew formula/cask generators route through it so there is a single escape implementation.