O'Reilly logo

The Book of Ruby by Huw Collingbourne

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Strings and Ranges

image with no caption

I’ve made use of strings in many of my programs so far. In fact, a string was featured in the very first program in the book. Here it is again:

puts 'hello world'

Although that first program used a string enclosed within single quotes, my second program used a string in double quotes:

print('Enter your name: ' )
name = gets()
puts( "Hello #{name}" )

Double-quoted strings do more work than single-quoted strings. In particular, they have the ability to evaluate bits of themselves as though they were programming code. To have something evaluated, you need to place it between a pair of curly brackets preceded by a hash mark ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required