Multiline Strings
In this page:
Multiline Strings
A Ruby string literal can span multiple lines directly inside quotes, preserving the line breaks as part of the string's content. This is simpler than using explicit \n characters for short multi-line text. For longer blocks of text, a heredoc (covered next) is usually more readable.
Note: Line breaks typed directly inside a quoted string become literal newline characters in the resulting string.
Example: Multiline Strings
message = "Line one
Line two
Line three"
puts message
puts message.lines.count
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: