Alle venerd? 17 agosto 2007, ashishwave ha scritto:
> Hi,
> how to do heredoc without interpolation and backslashes interpretation
> with arbitrary delimiter support (not just a single character)
>
> let me explain my point:
>
>  # here #{var1} gets interpolated
>  puts <<EOL
>     hello #{var1}
>   EOL
>
>  #here interpolation is off, backslashes interpretation is off, but
> you have to delimit it insingle character {}  @@ !!    .If your
> heredoc string itself is very complex and contains all ASCII
> charcaters and combo of backslashes then it becomes unsuable.
>   puts %Q{
>        hello #var1
>   }

Are you sure? If I remember correctly, %Q works like a double quoted string, 
so interpolation happens and backslashes are still interpreted. I think here 
you mean %q, instead.

>   SOMETHING LIKE THIS SHOULD BE ADDED TO/POSSIBLE IN RUBY
>   #HERE NOTHING GETS INTERPOLATED AND backslashes also remain there.
>   puts %Q{<<EOLLLL
>     @#$%^%&%&%&%SFSFSV #{abc} #{que} \r\n
>     \n
>   EOLLLL
>   }
>
>   Many times i have lots of jumbled up patterns from h/w device
> responses or i want to embed binary/image files itself inside ruby
> source code, then i am not able to do it with interpolation (which
> creates problem for #{  occurence ) or with backslash interpretation
> and also if i try to do it with single character delimters like %Q and
> {} [] !! @@ combination THEN single character } or ! or @ etc are more
> likely to appear in binary string itself ; creating problems for me.
> So i need my own relevant custom arbitrary length delimiter (like
> EOLLLL here) with this too, which is lot less less likely to appear in
> the heredoced string than a single delimited character.
>
>  So how to do it?
>
> bye :-)
> Ashish Ranjan
> ashishwave / yahoo.com

To get 'single quoted' heredoc, you need to single-quote the delimiter string:

puts <<'A_VERY_LONG_STRING'
hello #{var1}
A_VERY_LONG_STRING
=> hello #{var1}

(note that the delimiter string is only quoted at the beginning of the 
heredoc, not at the end).

I hope this helps

Stefano