From: John Feminella Date: 2011-02-14T09:49:30+09:00 Subject: Re: What does %q do? Whoops, small typo: > %q{abc} is equivalent to writing "abc". should read: > %q{abc} is equivalent to writing 'abc' (single quotes). By contrast, %Q{abc} is equivalent to writing "abc" (double quotes). You can see the difference when you try to substitute variables: > f = "apple" > %q{#{f}} => "\#{f}" > %Q{#{f}} => "apple" ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ On Sun, Feb 13, 2011 at 19:46, John Feminella wrote: > %q{abc} is equivalent to writing "abc". It's most useful when you have > a string literal that contains a lot of characters you'd need to > escape. Compare: > > "Gaba Luschi asked the ruby-talk list, \"What does %q do?\"" > > vs. > > %q{Gaba Luschi asked the ruby-talk list, "What does %q do?"} > > And note they're equal: > >> a = %q{Gaba Luschi asked the ruby-talk list, "What does %q do?"} >> b = "Gaba Luschi asked the ruby-talk list, \"What does %q do?\"" > >> a == b >  => true > > ~ jf > -- > John Feminella > Principal Consultant, BitsBuilder > LI: http://www.linkedin.com/in/johnxf > SO: http://stackoverflow.com/users/75170/ > > > > On Sun, Feb 13, 2011 at 19:39, Gaba Luschi wrote: >> What does %q do in ruby? >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> >