Robert Klemme
1/14/2007 12:53:00 PM
On 14.01.2007 06:42, Nobuyoshi Nakada wrote:
> Hi,
>
> At Sun, 14 Jan 2007 14:20:54 +0900,
> Robert James wrote in [ruby-talk:233900]:
>> Is there an idiomatic way to continue a long quote on a separate line,
>> or should I just do:
>>
>> "If you need help," +
>> " please dial the operator"
>
> # string literal concatenation
> puts "If you need help," > " please dial the operator"
>
> # escaping new lines
> puts "If you need help,> please dial the operator"
>
> # ditto, with here doc
> puts <<EOS
> If you need help,> please dial the operator
> EOS
Alternative to escaping new lines is replacement:
irb(main):004:0> s="foo
irb(main):005:0" bar
irb(main):006:0" baz".gsub! "\n", ' '
=> "foo bar baz"
irb(main):007:0> s
=> "foo bar baz"
Of course, this is less efficient because it's done at runtime - but
might be ok for constants.
This also works with heredocs.
robert