Forum: Ruby # please explain this syntax

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
96bb15ec886c45a93e0f32bb0b2e69c8?d=identicon&s=25 Kevin Abel (bklabel1)
on 2016-09-01 17:32
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
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2016-09-02 00:17
That's the syntax for Interpolation in a double-quoted string. Anything
between the braces will be evaluated and inserted into the string.
4828d528e2e46f7c8160c336eb332836?d=identicon&s=25 Robert Heiler (shevegen)
on 2016-09-03 03:47
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"
96bb15ec886c45a93e0f32bb0b2e69c8?d=identicon&s=25 Kevin Abel (bklabel1)
on 2016-09-17 00:08
Joel Pearson 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
This topic is locked and can not be replied to.