Let's see the following case:
We can also write above code as shown below.
Notice that instead of
concatenating the two
strings with a +
sign,
we are using #{ }
.
If the string is a 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 a single quoted string.
Let's test that: