Use of %() for Strings

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?

Thanks, Dave

The main advantage of %() is it ignores balanced parentheses inside the string. That makes it handy for quoting code.


code = %( foo(bar(3)) )

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!="";})