Learn Ruby
String
3.27
Lesson

Interpolation using double quoted string

Let’s see the following case.

We can also write above code as shown below.

Notice that instead of concatenating the two string with a + sign in this case we are using #{ }. If the string is double quoted string then Ruby will try to evaluate the code inside the { }. This is called String Interpolation.

Let’s see more examples of string interpolation.

Note that string interpolation only works if the string is using double quotes. String interpolation does not work with single quoted string. Let’s test that.