Ruby has classically supported the following literals:
%q[quack quack] #=> "quack quack"
%r[quack quack] #=> /quack quack/
%w[quack quack] #=> ["quack", "quack"]
%x[echo quack quack] #=> "quack quack\n"
My understanding of the origin of those are as follows:
%q[] is for quotes%r[] is for regex%w[] is for words%x[] is for executeRuby 2.0 introduced the %i notation:
%i[quack quack] #=> [:quack, :quack]
Why i?
It's probably a reference to the String#intern method used to get a symbol from a string.
"foo".intern #=> :foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With