Why use heredoc in doublequotes?

When you can do like this:

ruby a.rb
“im some text\n”
cat a.rb
str = <<TEXT.squeeze(“o”)
im soooome text
TEXT
p str

What is the rationale for doing <<“TEXT” ?

Have I misunderstood it?

···


Simon Strandgaard

I don’t really understand what you’re squeezing is supposed to show, the
double quote is for symetry with the single quote, AFAICT:

irb(main):001:0> f=“hi”
“hi”
irb(main):002:0> puts <<TEXT
irb(main):003:0" a #{f}
irb(main):004:0" TEXT
a hi
nil
irb(main):005:0> puts <<‘TEXT’
irb(main):006:0’ a #{f}
irb(main):007:0’ TEXT
a #{f}
nil

Sam

Quoteing neoneye@adslhome.dk, on Wed, Mar 17, 2004 at 04:44:33AM +0900:

···

When you can do like this:

ruby a.rb
“im some text\n”
cat a.rb
str = <<TEXT.squeeze(“o”)
im soooome text
TEXT
p str

What is the rationale for doing <<“TEXT” ?

Have I misunderstood it?


Simon Strandgaard

“Simon Strandgaard” neoneye@adslhome.dk schrieb im Newsbeitrag
news:pan.2004.03.16.19.37.24.107822@adslhome.dk…

When you can do like this:

ruby a.rb
“im some text\n”
cat a.rb
str = <<TEXT.squeeze(“o”)
im soooome text
TEXT
p str

What is the rationale for doing <<“TEXT” ?

Have I misunderstood it?

IMHO “<<TEXT” is equivalent to <<TEXT with the only difference that you
can use white space in the delimiter (see example d):

irb(main):002:0> a=<<HERE
irb(main):003:0" 5+2=#{5+2}
irb(main):004:0" HERE
=> “5+2=7\n”
irb(main):005:0> b=<<“HERE”
irb(main):006:0" 5+2=#{5+2}
irb(main):007:0" HERE
=> “5+2=7\n”
irb(main):008:0> c=<<‘HERE’
irb(main):009:0’ 5+2=#{5+2}
irb(main):010:0’ HERE
=> “5+2=#{5+2}\n”
irb(main):024:0> d=<<“HERE AM I”
irb(main):025:0" 5+2=#{5+2}
irb(main):026:0" HERE AM I
=> “5+2=7\n”
irb(main):027:0> d=<<HERE AM I
irb(main):028:0" 5+2=#{5+2}
irb(main):029:0" HERE AM I
irb(main):030:0" HERE
SyntaxError: compile error
(irb):27: syntax error
d=<<HERE AM I
^
from (irb):27
irb(main):031:0>

Regards

robert

“Simon Strandgaard” neoneye@adslhome.dk schrieb im Newsbeitrag
news:pan.2004.03.16.19.37.24.107822@adslhome.dk…

When you can do like this:

ruby a.rb
“im some text\n”
cat a.rb
str = <<TEXT.squeeze(“o”)
im soooome text
TEXT
p str

What is the rationale for doing <<“TEXT” ?

Have I misunderstood it?

IMHO “<<TEXT” is equivalent to <<TEXT with the only difference that you
can use white space in the delimiter (see example d):
[snip]
irb(main):024:0> d=<<“HERE AM I”
irb(main):025:0" 5+2=#{5+2}
irb(main):026:0" HERE AM I
=> “5+2=7\n”

Space the final frontier…
Thanks Robert for clearing that out :wink:

However I see doublequoted heredocs everywhere… I don’t think
there is a common understanding of what it does (yet).

···

On Wed, 17 Mar 2004 09:12:23 +0100, Robert Klemme wrote:


Simon Strandgaard

“Simon Strandgaard” neoneye@adslhome.dk schrieb im Newsbeitrag
news:pan.2004.03.16.19.37.24.107822@adslhome.dk…

When you can do like this:

ruby a.rb
“im some text\n”
cat a.rb
str = <<TEXT.squeeze(“o”)
im soooome text
TEXT
p str

What is the rationale for doing <<“TEXT” ?

Have I misunderstood it?

IMHO “<<TEXT” is equivalent to <<TEXT with the only difference that you
can use white space in the delimiter (see example d):

and you can delim with tokens reserved for ruby’s syntax:

~/eg/ruby > cat heredoc.rb
s = ‘foobar’

p <<“<<”
#{ s }
<<

~/eg/ruby > ruby heredoc.rb
" foobar\n"

-a

···

On Wed, 17 Mar 2004, Robert Klemme wrote:

irb(main):002:0> a=<<HERE
irb(main):003:0" 5+2=#{5+2}
irb(main):004:0" HERE
=> “5+2=7\n”
irb(main):005:0> b=<<“HERE”
irb(main):006:0" 5+2=#{5+2}
irb(main):007:0" HERE
=> “5+2=7\n”
irb(main):008:0> c=<<‘HERE’
irb(main):009:0’ 5+2=#{5+2}
irb(main):010:0’ HERE
=> “5+2=#{5+2}\n”
irb(main):024:0> d=<<“HERE AM I”
irb(main):025:0" 5+2=#{5+2}
irb(main):026:0" HERE AM I
=> “5+2=7\n”
irb(main):027:0> d=<<HERE AM I
irb(main):028:0" 5+2=#{5+2}
irb(main):029:0" HERE AM I
irb(main):030:0" HERE
SyntaxError: compile error
(irb):27: syntax error
d=<<HERE AM I
^
from (irb):27
irb(main):031:0>

Regards

robert

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: Solar-Terrestrial Physics Data | NCEI
TRY :: for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done
===============================================================================

“Simon Strandgaard” neoneye@adslhome.dk schrieb im Newsbeitrag
news:pan.2004.03.17.12.05.50.515961@adslhome.dk…

“Simon Strandgaard” neoneye@adslhome.dk schrieb im Newsbeitrag
news:pan.2004.03.16.19.37.24.107822@adslhome.dk…

When you can do like this:

ruby a.rb
“im some text\n”
cat a.rb
str = <<TEXT.squeeze(“o”)
im soooome text
TEXT
p str

What is the rationale for doing <<“TEXT” ?

Have I misunderstood it?

IMHO “<<TEXT” is equivalent to <<TEXT with the only difference that
you
can use white space in the delimiter (see example d):
[snip]
irb(main):024:0> d=<<“HERE AM I”
irb(main):025:0" 5+2=#{5+2}
irb(main):026:0" HERE AM I
=> “5+2=7\n”

Space the final frontier…

:-))

Thanks Robert for clearing that out :wink:

You’re welcome.

However I see doublequoted heredocs everywhere… I don’t think
there is a common understanding of what it does (yet).

IMHO “#{” and “#$” are rare enough that it doesn’t hurt to use <<HERE - at
least you save two chars of typing over <<‘HERE’. :slight_smile:

robert
···

On Wed, 17 Mar 2004 09:12:23 +0100, Robert Klemme wrote:

[snip]

~/eg/ruby > cat heredoc.rb
s = ‘foobar’

p <<“<<”
#{ s }
<<

~/eg/ruby > ruby heredoc.rb
" foobar\n"

I bet this can be useful for making an obscure compact quine.

:wink:

···

On Wed, 17 Mar 2004 09:18:30 -0700, Ara.T.Howard wrote:


Simon Strandgaard

Hi –

···

On Wed, 17 Mar 2004, Robert Klemme wrote:

IMHO “#{” and “#$” are rare enough that it doesn’t hurt to use <<HERE - at
least you save two chars of typing over <<‘HERE’. :slight_smile:

Yes, though you might lose them again if you have any '' characters
that need escaping :slight_smile:

David


David A. Black
dblack@wobblini.net

[snip]

~/eg/ruby > cat heredoc.rb
s = ‘foobar’

p <<“<<”
#{ s }
<<

~/eg/ruby > ruby heredoc.rb
" foobar\n"

I bet this can be useful for making an obscure compact quine.

:wink:

Since Ruby doesn’t care what you use as delimiters, usually…

%q delimited_with_spaces .inspect.display
“delimited_with_spaces”=>nil
%q delimited with plain 'ol tabs .inspect.display
“delimited with plain 'ol tabs”=>nil
%q
?> and with newlines?!?
?> .inspect.display
“and with newlines?!?”=>nil
%q^Hbackspaces are stranger yet^H.inspect.display
“backspaces are stranger yet”=>nil
%q^CBut the interrupt character really takes the
cake^C.inspect.display
“But the interrupt character really takes the cake”=>nil

I beg you, though – please don’t take advantage of the fact that you
can delimit strings with interrupts!!! :wink:

–Mark

···

On Mar 17, 2004, at 9:14 AM, Simon Strandgaard wrote:

On Wed, 17 Mar 2004 09:18:30 -0700, Ara.T.Howard wrote:

“Mark Hubbart” discord@mac.com schrieb im Newsbeitrag
news:C3ED58B4-783A-11D8-90E1-000502FDD5CC@mac.com

[snip]

~/eg/ruby > cat heredoc.rb
s = ‘foobar’

p <<“<<”
#{ s }
<<

~/eg/ruby > ruby heredoc.rb
" foobar\n"

I bet this can be useful for making an obscure compact quine.

:wink:

Since Ruby doesn’t care what you use as delimiters, usually…

%q delimited_with_spaces .inspect.display
“delimited_with_spaces”=>nil
%q delimited with plain 'ol tabs .inspect.display
“delimited with plain 'ol tabs”=>nil
%q
?> and with newlines?!?
?> .inspect.display
“and with newlines?!?”=>nil
%q^Hbackspaces are stranger yet^H.inspect.display
“backspaces are stranger yet”=>nil
%q^CBut the interrupt character really takes the
cake^C.inspect.display
“But the interrupt character really takes the cake”=>nil

I beg you, though – please don’t take advantage of the fact that you
can delimit strings with interrupts!!! :wink:

This thread goes down the dark side of Ruby… schudder
:slight_smile:

robert
···

On Mar 17, 2004, at 9:14 AM, Simon Strandgaard wrote:

On Wed, 17 Mar 2004 09:18:30 -0700, Ara.T.Howard wrote: