# please explain this syntax

I searched on # in this forum before asking this question. One post
said that line numbers were added in front of the code so that it can be
discussed. I did not see the code. Other search matches lead to more
complicated questions.

My question:
puts “My statement: #{statement}” please explain what the # sign and
the parameter in the {} are doing.

I have a few more syntax questions but I will ask them in separate
topics.

Thanks,

Kevin

That’s the syntax for Interpolation in a double-quoted string. Anything
between the braces will be evaluated and inserted into the string.

Ruby will perform a substitution on #{} with the variable.

x = '123'
y = "Hello #{x}"

if you output y in irb you will see it is a string with this value:

"Hello 123"

Joel P. wrote in post #1184924:

That’s the syntax for Interpolation in a double-quoted string. Anything
between the braces will be evaluated and inserted into the string.

Joel,
It seems like a nice way to do string concatenation. I would have never
thought of this idea. I cannot wait to get further into ruby to use
this.
Thanks,
Kevin