%Q
The string used to replace the double quotation marks. When you need to put a lot of quotes in the string, you can use the following method without adding a backslash (\ ") to the quotation marks.
%Q (Joe said: "Frank said:"#{what_frank_said}"")"Joe said:""hello!" " "
(
...)
Other non-alphanumeric symbols or paired symbols can also be substituted, such as ..., ..., ..., ... [
]
!
!
+
+
{
}
, <
>
...,........ such as.
The following wording is all equivalent to the above:
%q! Joe said: "Frank said:"#{what_frank_said} ""! %q[joe said: "Frank said:"#{what_frank_said}""%q+joe said: "Frank said:"#{What_ Frank_said}"" +
In addition, writing can be omitted Q
:
%/joe said: "Frank said:" #{what_frank_said} ""/"Joe said:"
%q
%Q
similar, but represents a single-quote string
%q (Joe said: ' Frank said: ' #{what_frank_said} ')"Joe said: ' Frank said: '\#
%W
The syntax is approximate to the %Q
array in which the elements are enclosed in double quotation marks.
%W (#{foo} bar withspace)["foo" "Bar" "Bar withspace"
%w
Used to represent an array where the elements are enclosed in quotation marks. It is strange that \
(slash spaces) will be converted
to (spaces), but the rest of the content will not.
\#e #{1}f)["a""B""C D""\ \#e""\#{1}f"]
%x
Use the ' method to execute a shell script and return the standard output content.
%x (echo foo:#{foo})"Foo:foo\ n
%r
Syntax is approximate %Q
and is used for regular expressions.
%r (/home/#{foo}"/\ \ home\ \
%s
Used to represent the symbol, but it does not convert content such as an expression
%s (foo): Foo%s (foo bar): "foo bar"%s (#{foo} bar): "\#{foo} bar"
%i
Syntax introduced after Ruby 2.0, used to generate a symbol array
2. 0. 0:%i (a b c)[: a: b: C
Original address: https://ruby-china.org/topics/18512
Ruby%Q,%Q,%W,%W,%x,%r,%s,%i