using %{} or %() also saves you from escaping embedded quotes in a
string, such as:
ActiveRecord::Base.connection.execute(%{select id,admin_comments
into outfile "#{file_name}.txt" fields terminated by ","
enclosed by
"""" from users where admin_comments!="";})
On 9/13/06, Brad Ediger <brad-sod+mMc99o6+XT7JhA+gdA@public.gmane.org>
wrote:>
>
>
>
> On Sep 13, 2006, at 8:46 PM, daveb wrote:
>
>
> I notice a lot of code throughout Rails uses this approach to build up
> a String:
>
> a = %(This is line one)
> a << %(This is line two)
> a
>
> After looking through two books I can''t seem to find a description
of
> what exactly %() does. Can anyone tell me what the benefits of using
> %() is?
>
> The main advantage of %() is it ignores balanced parentheses inside the
> string. That makes it handy for quoting code.
>
> Like:
>
> code = %( foo(bar(3)) )
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---