From: Paul van Delst Date: 2007-01-27T03:40:06+09:00 Subject: Re: Problem with stripping leading whitespace in here documents Phrogz wrote: > On Jan 25, 12:43 pm, s...@signature.invalid (Douglas Wells) wrote: >> "If the - [is] placed before the delimiter, then all leading >> whitespcae [sic] characters (tabs or spaces) are stripped from >> input lines and the line containing [the] delimiter. This >> allows here-documents within scripts to be indented in a natural >> fashion." > > Whoa, I've never seen that wording. That is entirely at odds with the > way Ruby behaves; as you note, no whitespace stripping occurs, except > that the '-' character allows the ENDDOC indicator to be indented. > > The lack of functionality that happens to be described in the document > that you quote above is what caused me to add this RCR: > http://www.rcrchive.net/rcrs/2 I vote for option 1 of the above proposal, since option 2 would break a lot of my current heredoc output. It would also be nice if one could specify how much of the END token leading spaces are removed (or replaced) from each line of the heredoc. Similar to the strip_output() method in... ri? (Can't remember exactly) That is, your class Foo def bar if whee print <<+END Hello World... Are you listening? END end end end produces Hello World... Are you listening? and then, for example, class Foo def bar if whee print <<+(2)END Hello World... Are you listening? END end end end produces Hello World... Are you listening? i.e. the leading spaces are replaced by the number specified after the +. (I'm lukewarm about the syntax, but you get the idea) I realise that would be equivalent to print <<+END Hello World... Are you listening? END but the "<<+(n)TOKEN" functionality would be a really nice feature because the number of indent spaces, n, can then be easily passed into methods interpolated in the heredoc that produce output you also want to be indented accordingly. I have that situation now where interpolated strings in heredocs are produced in the called method via another heredoc (I hope that makes sense.) cheers, paulv -- Paul van Delst Ride lots. CIMSS @ NOAA/NCEP/EMC Eddy Merckx