Difference between ‘%{}’, ‘%Q{}’, ‘%q{}’ in ruby string delimiters

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)