O'Reilly logo

Ruby Quick Syntax Reference by Matt Clements

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

image

Strings

String Literals

A string within Ruby is a sequence of one of more bytes, typically a set of characters. These can be created, manipulated, and output when required. Strings are generally wrapped in single or double quotation marks:

2.1.0 :001 > puts "Hello World"Hello World2.1.0 :001 > puts 'Hello World'Hello World

However if the string contains another double/single quote, these will need to be escaped in order for the string to be complete, and the code to compile:

2.1.0 :001'> puts 'Welcome to John's website'SyntaxError: (irb):5: syntax error, unexpected tIDENTIFIER, expecting end-of-inputputs 'Welcome to John's website' # ...

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