No trailing spaces after closing here doc tag?

Just had a frustrating thing come up. With the following:

var = <<-DOC
yo
DOC

… and trailing spaces after the final DOC, I get this:

C:\Temp>more zz.rb
  var = <<-DOC
    yo
  DOC


C:\Temp>ruby -v
ruby 1.8.0 (2003-08-04) [i386-mswin32]

C:\Temp>zz
C:/Temp/zz.rb:4: can't find string "DOC" anywhere before EOF
C:/Temp/zz.rb:1: syntax error

I get the same on ruby 1.6.6, windows.

Is this a bug?

I don’t need trailing spaces there, of course, and removing them makes
the problem go away. I just didn’t know they were there and when
embedded in some longer code the syntax error gets buried under another
one. (Well, I just spent 5 minutes trying to extract a standalone
example out of a long script of code to demonstrate, but couldn’t get
one that hid the here doc error).

···

Chris
http://clabs.org/blogki

Ruby insists on a newline following the here-doc closer.

···

“Chris Morris” chrismo@clabs.org wrote:

Just had a frustrating thing come up. With the following:

var = <<-DOC
yo
DOC

… and trailing spaces after the final DOC, I get this:


var = <<-DOC
yo
DOC
DOC
puts var

produces

#-> yo
#-> DOC

because the first appearance of DOC is actually 'DOC '.

Is this a bug?

Yes, but you fixed it :wink:

If an editor can be configured to strip trailing spaces
from lines, I use it.

daz

daz wrote:

Is this a bug?

Yes, but you fixed it :wink:

heh … yes.

If an editor can be configured to strip trailing spaces
from lines, I use it.

I thought my editor did this, but was surprised to see it doesn’t. I’d
have thought this would’ve bit me before this.

Anyway, thanks for the info.

···

Chris
http://clabs.org/blogki