Forum: Ruby Multi-line string

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5e7f3a5f140ffe0175a38875dce9a564?d=identicon&s=25 Nate Quash (bklynate)
on 2014-05-09 21:00
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?
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-05-09 22:09
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 topic is locked and can not be replied to.