Yes, this piece of code is perfectly correct !
This example uses a percent literal of type String
with % as delimiter.
The list of percent literal is as follows:
%
,%Q
,%q
(String)%s
(Symbol)%r
(Regexp)%x
(Backtick => Shell command)%W
,%w
(String array)%I
,%i
(Symbol array)
The delimiter is the character of your choice (almost…). The most interesting are the String and Symbol arrays. The difference between lowercase and uppercase is whether or not interpolation is performed.
Blank characters are not taken into account ("\n"
included). To include them, escape them with a "\"
.
Small question, does the following code produce an error?
Link to Ruby documentation for percent literal.