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 # from  w w w .ja  v  a  2s . c om
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 # from  w w w.  jav a2  s . co m
line capabilities! 
puts x

Result

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

Related Topic