nested #{expr} in strings

K

konsu

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
 
A

Assaph Mehr

if a double quoted string has a #{} block that evaluates to another doubl=
e
quoted string with another #{} block, will the resulting string be expan= ded
too?

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

Sean O'Halpin

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." :)

regards,
Sean
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: nested #{expr} in strings"

|> 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." :)

Yes, but still it's defined behavior.

matz.
 
S

Sean O'Halpin

|> i just checked and it seems so, but the question is whether this is we=
ll
|> 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." :)

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
 
K

konsu

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 ;-)

konstantin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top