My questions is: What do %w and % represent with respect to the
“block”? in the first case and the “array”? in the second? I cannot
find an explanation of either usage in the documentation.
My questions is: What do %w and % represent with respect to the
“block”? in the first case and the “array”? in the second? I cannot
find an explanation of either usage in the documentation.
They’re not really a block and an array - the %w can be followed by
the delimiter of your choice, and makes an array of the words between
the first and next instance of that delimiter. For example, each of
these:
%w == string.split(/\s+/) (maybe not exactly
that regexp, but basically it’s an array of the words–hence the w)
% == string, but without needing to escape the
quotes. It’s the same as using %Q (ie, it understands escape sequences
and interpolated expressions inside, while %q is a literal string)
Uh, seems my email never arrived? This is what I had written:
%w == string.split(/\s+/) (maybe not exactly
that regexp, but basically it’s an array of the words–hence the w)
% == string, but without needing to escape the
quotes. It’s the same as using %Q (ie, it understands escape sequences
and interpolated expressions inside, while %q is a literal string)
HTH
-foca
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.