December 2014
Intermediate to advanced
164 pages
2h 14m
English
CHAPTER 3
![]()
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' # ...
Read now
Unlock full access