Re: Onlamp tutorial - questions/comments

candlerb
Tue, 27 Feb 2007 14:45:30 -0000

On Feb 27, 2:13 pm, "Scott"
<tamosu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> The %Q is used to quote the contents... it usefulness becomes more
> apparent when you have lots of embedded single and double quotes.

Well, I know what %Q{..} is, but I still don''t see why it is needed
here.

We are calling a method, "link_to", with several arguments:  link_to
arg1, arg2, arg3

If I write %Q{#{arg1}}, or equivalently "#{arg1}", then I am:
1. evaluating arg1
2. if it''s not a string, calling its to_s method
3. inserting that string inside another string

It would make sense if I wanted to add some more text before or after
the argument: e.g. %Q{http://#{arg1}?foo=bar}. However I don''t see why
it''s needed here; it just looks like line noise. Maybe I am missing
something deep and fundamental and Rails will break without it, but if
so, I want to know what it is...