Next 3.2 Strings Prev

Strings

Usual syntaxAlternative syntaxResult
"Some 'string'"%Q{Some 'string'}Some 'string'
'It\'s "string" too'%q{It's "string" too}It's "string" too
"He said: \"It's fine\""%@He said: "It's fine"@He said: "It's fine"
`date`%x{date}Sat Oct 4 21:55:30 IST 2003

Here document construction:

myString = <<END_OF_STRING + "one more line\n"
This is multiline string, similar to double-quoted
string, but it always ends with a newline
END_OF_STRING

Substitution:
puts "Seconds in one day: #{24*60*60}"
puts "#{'X' * 3}Large in line #$."
Seconds in one day: 86400
XXXLarge in line 2

Next Ruby for Perl programmers Prev