Baham's Blog

Above all else, guard your heart.

Ruby's Multiline

How to show mutilines in Ruby’s code

In summary, there are 2 ways:

1 use %q{}

For example:

x = %q{ line1
line2
line3}

or use %q!! %q() and so on

2 use Here Document

And you can use here document

For example:

x = <<here_document
line1
line2
here_document

Use << start with some strings, like the abrove, use <<here_document

And ended with the strings.




The Original Link: http://baham.github.io/04_28_ruby-multi-line.html
If you want to reprint it, please do under the CC BY-NC-SA 4.0

Comments