From the course: Complete Guide to Ruby

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Strings: Escaping and interpolation

Strings: Escaping and interpolation - Ruby Tutorial

From the course: Complete Guide to Ruby

Strings: Escaping and interpolation

- [Instructor] In this movie, we'll learn about string escaping and string interpolation. Strings can be defined with double quotes or single quotes. We call these delimiters because they delimit the start and the end of the string. But there are some considerations to keep in mind when choosing which delimiter to use. The first consideration is whether the string delimiter is also contained inside the string. For example, it's fine to have a single quote inside a string that's delimited by double quotes, but a single quote inside a string that's delimited by single quotes is a problem. Ruby sees the first single quote and recognizes that it's the start of the string, and then when it encounters the second single quote, it thinks the string is done. Everything after is not included in the string and will probably create an error in the code. You would need to use a backslash in front of that second quote to escape it. Ruby now sees it as a simple single quote character inside the…

Contents