I was going through an online tutorial on ruby and found this \"General Delimited Strings\",
%{a word} # => \"a word\"
%Q{a word} # => \"a word\"
%q{
%q(no interpolation)
%Q(interpolation and backslashes)
%(interpolation and backslashes)
Example
$ str = 'sushant'
$ %q[#{str} "mane"]
=> "\#{str} \"mane\""
$ %Q[#{str} "mane"]
=> "sushant \"mane\""
$ %[#{str} "mane"]
=> "sushant \"mane\""
Here is some hints about them Ruby_Programming - The % Notation:
%Q[ ] - Interpolated String (default)
%q[ ] - Non-interpolated String (except for \ , [ and ])
Example :
x = "hi"
p %Q[#{x} Ram!] #= > "hi Ram!"
p %q[#{x} Ram!] #= > "\#{x} Ram!"
p %Q[th\e] #= > "th\e"
p %q[th\e] #= > "th\\e" # notice the \\ with %q[]
Another good resource Percent Strings
Besides
%(...)
which creates a String, The%
may create other types of object. As with strings, an uppercase letter allows interpolation and escaped characters while a lowercase letter disables them.