Multi-line string

Hi,

I recently came to ruby after spending a few months learning Python.

I was wondering if there is a way similar to Python’s triple quote ’ “”"

that allows for a comment to be printed on multi-lines

say for instance:

puts “The choice is yours kid: A) Shake down the owner
B) Rob the storekeeper”

You wanted this to print exactly in the format as you see here…

how would you do this?

The code you wrote is actually valid ruby, although you’ll need to
offset a bit because of “puts”.

irb(main):001:0> puts “The choice is yours kid: A) Shake down the owner
irb(main):002:0” B) Rob the storekeeper"
The choice is yours kid: A) Shake down the owner
B) Rob the storekeeper

If you’re writing complex multiline strings, you might want to have a
look at Heredocs:
http://rubyquicktips.com/post/4438542511/heredoc-and-indent

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs