Long quotes on multiple lines

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"

Robert J. wrote:

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"

Hmm, I don’t think you can…

if you do (which you can)

“If you need help
please dial the operator”

you’ll get ‘\n’ sneaked in there…

I think that using ‘+’ is the only way. Now the question is if that
affects performance at all… I wouldn’t know.

David K. wrote:

Robert J. wrote:

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"

Hmm, I don’t think you can…

if you do (which you can)

“If you need help
please dial the operator”

you’ll get ‘\n’ sneaked in there…

I think that using ‘+’ is the only way. Now the question is if that
affects performance at all… I wouldn’t know.

At a guess, I would say that using + means it has to go through
String#+. If you write something like

class String
alias old_plus :+
def + other
puts "adding strings “#{other}”
old_plus other
end
end

On the other hand, if you use a lexical construct like

“asdf asdf”
“asdf asdf”

Then the compiler probably does (or at least can do) literal string
concatenation at parse time.

ah ok, so this is the answer Robert was looking for:

“asdf asdf”
“asdf asdf”

I didn’t know how to do this either. Now I know. Cool

Robert J. wrote:

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"


Posted via http://www.ruby-forum.com/.

“one
two
three”
=> “one two three”

On 14.01.2007 06:42, Nobuyoshi N. wrote:

string literal concatenation

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

Nobuyoshi N. wrote:

string literal concatenation

puts “If you need help,”
" please dial the operator"

Is this deprecated and planned for removal at some point? I seem to
recall so.

Robert K.:

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”

Also, if you like something fancy:

require 'facet/string/margin'

x = %Q{
      | This
      |     is
      |       margin controlled!
      }.margin

Regards, Kalman

Hi,

At Sun, 14 Jan 2007 14:20:54 +0900,
Robert J. 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

Hi,

At Sun, 14 Jan 2007 14:55:31 +0900,
Joel VanderWerf wrote in [ruby-talk:233904]:

string literal concatenation

puts “If you need help,”
" please dial the operator"

Is this deprecated and planned for removal at some point? I seem to
recall so.

Maybe in the future, but it’s not deprecated nor planned yet
right now, although Matz has mentioned about it somewhere.

And, the last one included a new line at the end.
Instead, another one:

empty expression interpolation

p “If you need help,#{
} please dial the operator”