Chapter 3
Letters

We’ve learned all about numbers, but what about letters? Words? Text?

We refer to groups of letters in a program as strings. (You can think of beads with letters on them being strung together.) To make it easier to see just what part of the code is in a string, I’ll color strings 'like this'. Here are some strings:

'Hello.'
'Ruby rocks.'
'Nobody deserves a mime, Buffy.'
'Snoopy says #%^?&*@! when he stubs his toe.'
' '
''

As you can see, strings can have punctuation, digits, symbols, and spaces in them…more than just letters. That last string doesn’t have anything in it at all; we call that an empty string.

We used puts to print numbers; let’s try it with some strings:

puts ​'Hello, world!'
puts ​''
puts ​'Good-bye.'
Hello, world!
Good-bye.

Dig it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.215.117