A single line string that needs to be interpolated and embedded with double quotes uses% () (abbreviated as%Q). Multi-line string, preferably with Heredocs.
# bad (no interpolation needed)
% (<div class= "text" >some text</div>)
# should to be ' <div class= ' Text ' >some text</div> '
# Bad (no double-quotes)
% (the This is #{quality} style)
# should be ' this is #{qu Ality} style "
# bad (multiple lines)
% (<div>\n<span class= ' big ' >#{exclamation}</span>\n </div>)
# should be a heredoc.
# Good (requires interpolation, has quotes, single line)
% (<tr><td class= "name" >#{name}</td>)
No ' and ' strings do not use%q. Normal strings are more readable unless many characters need to be escaped.
# bad
name =%q (Bruce Wayne) Time
=%q (8 o ' clock)
question =%q ("What did for you say?")
# good
name = ' Bruce Wayne ' time
= ' 8 o ' clock '
question = ' What did you say? '
The%r method is only suitable for defining regular expressions that contain multiple/symbols.
# bad
%r (\s+)
# still-
%r (^/(. *) $)
# should be/^\/(. *) $/
# good
%r (^/blog/2011/(. *) $)
Do not use%x unless you have used an inverted quotation mark in the command you invoked (this is uncommon).
# bad
date =%x (date)
# good
date = ' Date '
echo =%x (echo ' Date ')
Do not use%s. Communities tend to use: "Some string" to create symbols that contain whitespace.
Use () with% literal, except for%r. Because curly braces often appear in regular expressions in many scenes, characters that are less common in many scenes, such as {as delimiters, may be a better choice, depending on the contents of the regular formula.
# bad
%w[one two three]
%q{"Test ' king!", John said.}
# good
%w (one Two three)
%q ("Test ' king!", John said.)