def attack
@damage = rand(@strength)
puts 'Did #{@damage} damage!'
end
end
Why doesn't rex.attack exhibit the desired behavior?
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$
Well, the #{} magic (called string interpolation if you
want to be super fancy) is possible only with
double-quoted strings; it can$B!G(Bt be done with
single-quoted ones.
On Sat, 16 Apr 2022 16:21:56 +0200, Martin KlaiberIDK what who you are
<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.rbAh, I see; according to p. 35 of the book,
| 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$
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^
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 285 |
Nodes: | 16 (2 / 14) |
Uptime: | 75:48:49 |
Calls: | 6,489 |
Calls today: | 2 |
Files: | 12,096 |
Messages: | 5,276,201 |