Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #7455

Re: question regarding syntax of #{rand()}

From Benjamin L. Russell <DekuDekuplex@Yahoo.com>
Newsgroups comp.lang.ruby
Subject Re: question regarding syntax of #{rand()}
Message-ID <rtdo5hlbh8jm2aglnk630j5qm4kejdcnoo@4ax.com> (permalink)
References <o8cl5h12k365eosq8aro47si1reckooud6@4ax.com> <210rii-cgn.ln1@tempo.martinkl.dialup.fu-berlin.de>
Organization Forte - www.forteinc.com
Date 2022-04-18 00:58 +0900

Show all headers | View raw


On Sat, 16 Apr 2022 16:21:56 +0200, Martin Klaiber
<usenet.martinkl@gmx.de> wrote:

>Here it works when using double-quotes instead of single:
>
>| puts "Did #{@damage} damage!"
>
>Proof:
>
>| martinkl@maurice:~/src/eigene/ruby$ ./guard_dog.rb
>| Did 0 damage!
>| martinkl@maurice:~/src/eigene/ruby$ ./guard_dog.rb
>| Did 6 damage!
>| martinkl@maurice:~/src/eigene/ruby$ ./guard_dog.rb
>| Did 2 damage!
>| martinkl@maurice:~/src/eigene/ruby$

Ah, I see; according to p. 35 of the book,

> Well, the #{} magic (called string interpolation if you 
> want to be super fancy) is possible only with 
> double-quoted strings; it can’t be done with 
> single-quoted ones.

Apparently, I had better either differentiate more closely between
single and double quotes when reading the book, or increase my intake
of ginkgo biloba (which I have been too stingy to take recently) to
increase my memory.

Thank you for your response; issue resolved.
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Computer Science Document Proofreader/Editor
"Furuike ya, kawazu tobikomu mizu no oto." -- Matsuo Basho^ 

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

question regarding syntax of #{rand()} Benjamin L. Russell <DekuDekuplex@Yahoo.com> - 2022-04-16 21:16 +0900
  Re: question regarding syntax of #{rand()} Martin Klaiber <usenet.martinkl@gmx.de> - 2022-04-16 16:21 +0200
    Re: question regarding syntax of #{rand()} Benjamin L. Russell <DekuDekuplex@Yahoo.com> - 2022-04-18 00:58 +0900
      Re: question regarding syntax of #{rand()} Sophia Ding <2027dings78@moundsviewschools.org> - 2022-05-10 09:44 -0700

csiph-web