In Ruby, we can create a template string using backticks (``) or the %() notation. Both methods allow us to interpolate variables into a string.
Here is an example using backticks:
main.rb42 chars3 lines
In this example, the value of name
is interpolated into the backtick string using #{name}. The resulting value of message
will be "Hello, John!".
Alternatively, we can use the %() notation to achieve the same result:
main.rb44 chars3 lines
The %Q notation is a shorthand for a double-quoted string that allows interpolation. The resulting value of message
will be "Hello, John!".
gistlibby LogSnag