Nested #{expr} in strings

hello,

if a double quoted string has a #{} block that evaluates to another double
quoted string with another #{} block, will the resulting string be expanded
too?

for example, in ActiveRecord i have:

acts_as_list :scope => 'parent_id #{self.parent_id.nil? ? "is null" :
"=#{self.parent_id}"}'

i just checked and it seems so, but the question is whether this is well
defined behaviour and not just a coincidence.

thanks
konstantin

if a double quoted string has a #{} block that evaluates to another double
quoted string with another #{} block, will the resulting string be expanded
too?

It's a feature :slight_smile:
There is no limit to the nesting, beyond physical memory.

i just checked and it seems so, but the question is whether this is well
defined behaviour and not just a coincidence.

It's a mystery. As Matz said (ruby-talk/82247) "Only Nobu knows this
part of the parser." :slight_smile:

regards,
Sean

Hi,

···

In message "Re: nested #{expr} in strings" on Wed, 5 Oct 2005 22:02:36 +0900, Sean O'Halpin <sean.ohalpin@gmail.com> writes:

i just checked and it seems so, but the question is whether this is well
defined behaviour and not just a coincidence.

It's a mystery. As Matz said (ruby-talk/82247) "Only Nobu knows this
part of the parser." :slight_smile:

Yes, but still it's defined behavior.

              matz.

>> i just checked and it seems so, but the question is whether this is well
>> defined behaviour and not just a coincidence.
>
>It's a mystery. As Matz said (ruby-talk/82247) "Only Nobu knows this
>part of the parser." :slight_smile:

Yes, but still it's defined behavior.

                                                       matz.

Indeed. And a lot of work went into making it possible.

I guess I was being a bit too flippant.

As a note to konsu: in general, if something in Ruby works the way you
want it to, you can safely assume that it was put there deliberately.

Regards,

Sean

thanks, i guess i spent too much time working for commercial software
companies, so now working code makes me suspicious that it might be working
just by chance :wink:

konstantin

···

As a note to konsu: in general, if something in Ruby works the way you
want it to, you can safely assume that it was put there deliberately.

Regards,

Sean