Ruby - String here document

Introduction

Here document works in a similar way, except that the delimiter can be many characters long.

Demo

x = <<END_MY_STRING_PLEASE 
This is the string 
And a second line # from   w  ww  .j  a v a2s.c  om
END_MY_STRING_PLEASE 
puts x

Result

Here, << marks the start of the string literal and is followed by a delimiter of your choice.

We used END_MY_STRING_PLEASE.

The string literal then starts from the next new line and finishes when the delimiter is repeated again on a line on its own.

Related Topics