0

How could I split a long string into multiple lines in Ruby?

I have some long string:

`This is a long and awesome command!`

How could I write it in two lines? Note that there is NO CR or LF in the string.

Thanks!

xuhdev
  • 8,018
  • 2
  • 41
  • 69
  • 1
    How about this? http://stackoverflow.com/questions/2337510/ruby-can-i-write-multi-line-string-with-no-concatenation – squiguy Mar 21 '13 at 04:42
  • @squiguy That's referring to strings *in code*. I believe the OP wants to perform "word wrapping" based on a fixed maximum width. – Jonathon Reinhart Mar 21 '13 at 04:44
  • @JonathonReinhart It's hard to say exactly. I obviously am just curious. – squiguy Mar 21 '13 at 04:46
  • @JonathonReinhart You're right. What you said is exactly what I am looking for. – xuhdev Mar 21 '13 at 04:47
  • @squiguy Your link works for a regular string, but do you have any idea of backticks quoted strings? Do I have to write something like: `#{some_string}` by assigning the variable `some_string` first? – xuhdev Mar 21 '13 at 04:51
  • 1
    `Do I have to write something like: #{some_string} by assigning the variable some_string first?` Think about that for a bit. If you don't assign anything to `some_string`, what will be the value of the entire string? Try it in IRB and see. – the Tin Man Mar 21 '13 at 04:58
  • @theTinMan I didn't see your point... What I mean is, am I able to write a string splited in multiple lines to execute the shell command directly, instead of assigning some variables as workarounds. – xuhdev Mar 21 '13 at 07:12
  • possible duplicate of [Ruby Backticks - break command into multiple lines?](http://stackoverflow.com/questions/9998518/ruby-backticks-break-command-into-multiple-lines) – Cristian Lupascu Mar 21 '13 at 07:31

0 Answers0