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.
90e6cf0573abc6cc55afefe73c5bb0a3?d=identicon&s=25 Nate Q. (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?
9627ec27e4fb3a18be02133b4ddaa901?d=identicon&s=25 Joel P. (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.