Hi,
I recently joined this list, so please forgive me if this question has
been asked recently. I am wondering about the precise semantics of <<
and <<-. "Programming Ruby"[1] and the pseudo-BNFs[2][3] say that you
can use a quoted string after <<. As I see it, this means I should be
able to able to use the #{expr} construct inside this string, like this:
print <<"#{2+2}"
foobar
#{4}
This is, however, not the way my installation of Ruby (1.8.1) works.
What I am wondering is, is this the expected behaviour and are both the
book and the pseudo-BNFs wrong, or is this some form of bug in the
interpreter?
My guess would be that it's an omission in the documentation. I don't
think you can do interpolation in the string. Basically it's not a
Ruby string but an idendifier and the quotation announces differnt
behaviro. After all, what do you gain by a computed terminator of a
here document? I don't think that's useful.
2005/8/31, Anders Höckersten <chucky@dtek.chalmers.se>:
Hi,
I recently joined this list, so please forgive me if this question has
been asked recently. I am wondering about the precise semantics of <<
and <<-. "Programming Ruby"[1] and the pseudo-BNFs[2][3] say that you
can use a quoted string after <<. As I see it, this means I should be
able to able to use the #{expr} construct inside this string, like this:
print <<"#{2+2}"
foobar
#{4}
This is, however, not the way my installation of Ruby (1.8.1) works.
What I am wondering is, is this the expected behaviour and are both the
book and the pseudo-BNFs wrong, or is this some form of bug in the
interpreter?
Hi,
I recently joined this list, so please forgive me if this question has
been asked recently. I am wondering about the precise semantics of <<
and <<-. "Programming Ruby"[1] and the pseudo-BNFs[2][3] say that you
can use a quoted string after <<. As I see it, this means I should be
able to able to use the #{expr} construct inside this string, like this:
print <<"#{2+2}"
foobar
#{4}
The purpose of quoting the here-document label is to make the
text be treated as though it were enclosed in single quotes.
···
----------------------------------------------
puts <<'HERE'
#{3**3} bells.
HERE
puts <<"HERE"
#{3**3} bells.
HERE
puts <<HERE
#{3**3} bells.
HERE
------------------------------------------------
2005/8/31, Robert Klemme <shortcutter@googlemail.com>:
2005/8/31, Anders Höckersten <chucky@dtek.chalmers.se>:
> Hi,
> I recently joined this list, so please forgive me if this question has
> been asked recently. I am wondering about the precise semantics of <<
> and <<-. "Programming Ruby"[1] and the pseudo-BNFs[2][3] say that you
> can use a quoted string after <<. As I see it, this means I should be
> able to able to use the #{expr} construct inside this string, like this:
> print <<"#{2+2}"
> foobar
> #{4}
>
> This is, however, not the way my installation of Ruby (1.8.1) works.
> What I am wondering is, is this the expected behaviour and are both the
> book and the pseudo-BNFs wrong, or is this some form of bug in the
> interpreter?
My guess would be that it's an omission in the documentation. I don't
think you can do interpolation in the string. Basically it's not a
Ruby string but an idendifier and the quotation announces differnt
behaviro. After all, what do you gain by a computed terminator of a
here document? I don't think that's useful.