No trailing spaces after closing here doc tag?

C

Chris Morris

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).
 
D

daz

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

var = <<-DOC
yo
DOC

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

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

----
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 ;-)

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


daz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top