Ruby - String across multiple lines

Introduction

To make a string that can span multiple lines, try this:

Demo

x = %q{This is a test 
of the multi # w w w .java  2s.  c  o  m
line capabilities} 

puts x

Result

Here, the quotation marks have been replaced with %q{ and }.

You don't have to use curly brackets, though.

You can use < and >, ( and ), or simply two other delimiters of your choice, such as ! and !.

This code works in exactly the same way:

Demo

x = %q!This is a test 
of the multi # w  w  w.j a v  a 2 s.c  om
line capabilities! 
puts x

Result

If delimiter characters are present in your string, your string literal will end early.

Related Topic