%w| a b c| %w_a b c_ %w<a b c> all work

%w|a b c|

%w_a b c_

%w

all work
is there an official doc or book that says so?

seems like the first character that after “%w” can be used as a
delimiter.

Hi –

On Sat, 22 Sep 2007, SpringFlowers AutumnMoon wrote:

delimiter.
Pretty much, though some characters won’t work. My favorite % trick
is:

ruby -e 'p %q abc ’
“abc”

:slight_smile:

David

SpringFlowers AutumnMoon wrote:

all work
is there an official doc or book that says so?

If you look up %w at the beginning of the index in pickaxe2, it directs
you to p. 322, which has a section titled Arrays. In that section, it
says %w is a form of general delimited input described on p. 318-319.
Looking on those pages, it says:

“Following the type character is a delimiter, which can be any
nonalphabetic or nonmultibyte character. If the delimiter is one of the
characters (, [, {, or <, …blah, blah, blah…[the ending character
must be: ), ], }, or > respectively]. For all other delimiters, [the
ending character is the next occurrence of the starting delimiter].”

7stud – wrote:

“Following the type character is a delimiter, which can be any
nonalphabetic or nonmultibyte character. If the delimiter is one of the
characters (, [, {, or <, …blah, blah, blah…[the ending character
must be: ), ], }, or > respectively]. For all other delimiters, [the
ending character is the next occurrence of the starting delimiter].”

I just wanted to point out that the statement that the delimiter can be
any “nonalphabetic or nonmultibyte” character appears to be false. The
character ‘2’ meets the condition of being “nonalphabetic or
nonmultibyte”, yet it produces an error:

arr = %w_a b c_
p arr #[“a”, “b”, “c”]

arr = %w2a b c2
p arr

r4test.rb:4: unknown type of %string
arr = %w1a b c1
^
r4test.rb:4: syntax error
arr = %w1a b c1
^

It looks like the docs should say:

…a delimiter, which can be any character
that is nonalphabetic and nonmultibyte."

On Sep 22, 4:02 am, SpringFlowers AutumnMoon
[email protected] wrote:

%w|a b c|

%w_a b c_

%w

all work
is there an official doc or book that says so?

http://phrogz.net/ProgrammingRuby/language.html#generaldelimitedinput

7stud – wrote:

r4test.rb:4: unknown type of %string
arr = %w1a b c1
^
r4test.rb:4: syntax error
arr = %w1a b c1
^

Whoops. I pasted the wrong error message. It should be:

r4test.rb:4: unknown type of %string
arr = %w2a b c2
^
r4test.rb:4: syntax error
arr = %w2a b c2
^

David A. Black wrote:

all work

:slight_smile:

I enjoy doing this:

irb(main):002:0> %w) foo bar)
=> [“foo”, “bar”]

William J. wrote:

I enjoy doing this:

irb(main):002:0> %w) foo bar)
=> [“foo”, “bar”]

You, sir, are demented %w)

(And, no, I don’t know what that means as a smiley.)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs