How to heredoc without interpolation and backslash interpretation with arbitrary length delimiter support

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
  }

  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 :slight_smile:
Ashish Ranjan
ashishwave@yahoo.com

Here Docs

<<identifier - interpolated, goes until identifier
<<"identifier" - same thing
<<'identifier' - no interpolation
<<-identifier - you can indent the identifier by using "-" in front

···

On 8/17/07, ashishwave <ashishwave@gmail.com> wrote:

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
  }

  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?

Hi,

I'm not quite sure, but are you not looking for something like
test = <<-'EOS'
nothing should need 'delimiters' in \here
EOS

Sorry if i missed the point, still quite new to Ruby

Nick

···

On 8/17/07, ashishwave <ashishwave@gmail.com> wrote:

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
  }

  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 :slight_smile:
Ashish Ranjan
ashishwave@yahoo.com

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 :slight_smile:
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

ya, i actually meant %q (not %Q) i mistyped

anyway, thanks jano, it worked
bye :slight_smile:
Ashish