Ruby/String/String Literal

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Содержание

Alternate single and double quotes

puts "I said, "Hello."" or "I said, "Hello.""



Enclose strings in double quotes

puts "Enclose strings in double quotes"



Enclose strings in single quotes

puts "Enclose strings in single quotes"



Escape quotation marks with a backslash

puts "I said, \" Hello.\"" or "I said, \"Hello.\""



Make the print method skip to the next line without a HERE document, use the newline character, \n.

print "Now is \nthe time."



mix single and double quotes, as long as Ruby can keep them straight

puts "say, "No"?"



Three-line string literal

"This string literal
has two lines \
but is written on three"



XML uses paired angle brackets:

puts %<<book><title>Ruby in a Nutshell</title></book>>  # This works



you cannot mix double-quoted text inside a double-quoted string, or single-quoted text inside a single-quoted string

puts "I said, "Hello.""