# %w| a b c| %w\_a b c\_ %w\<a b c\> all work

**URL:** <https://www.ruby-forum.com/t/w-a-b-c-w-a-b-c-w-a-b-c-all-work/115245>\
**Category:** Ruby\
**Created:** [September 22, 2007, 12:02pm UTC](https://www.ruby-forum.com/t/w-a-b-c-w-a-b-c-w-a-b-c-all-work/115245 "2007-09-22T12:02:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 22, 2007, 12:02pm UTC](https://www.ruby-forum.com/t/w-a-b-c-w-a-b-c-w-a-b-c-all-work/115245/1 "2007-09-22T12:02:34Z")

</div>

%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.

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 22, 2007, 1:17pm UTC](https://www.ruby-forum.com/t/w-a-b-c-w-a-b-c-w-a-b-c-all-work/115245/2 "2007-09-22T13:17:57Z")

</div>

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”

🙂

David

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 22, 2007, 1:42pm UTC](https://www.ruby-forum.com/t/w-a-b-c-w-a-b-c-w-a-b-c-all-work/115245/3 "2007-09-22T13:42:33Z")

</div>

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].”

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 22, 2007, 10:28pm UTC](https://www.ruby-forum.com/t/w-a-b-c-w-a-b-c-w-a-b-c-all-work/115245/4 "2007-09-22T22:28:34Z")

</div>

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."

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 22, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/w-a-b-c-w-a-b-c-w-a-b-c-all-work/115245/5 "2007-09-22T17:11:28Z")

</div>

On Sep 22, 4:02 am, SpringFlowers AutumnMoon  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://phrogz.net/ProgrammingRuby/language.html#generaldelimitedinput)

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 22, 2007, 11:40pm UTC](https://www.ruby-forum.com/t/w-a-b-c-w-a-b-c-w-a-b-c-all-work/115245/6 "2007-09-22T23:40:43Z")

</div>

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  
^

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 23, 2007, 12:36pm UTC](https://www.ruby-forum.com/t/w-a-b-c-w-a-b-c-w-a-b-c-all-work/115245/7 "2007-09-23T12:36:10Z")

</div>

David A. Black wrote:

> > all work
> 
> 🙂

I enjoy doing this:

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

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [September 23, 2007, 9:35pm UTC](https://www.ruby-forum.com/t/w-a-b-c-w-a-b-c-w-a-b-c-all-work/115245/8 "2007-09-23T21:35:14Z")

</div>

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.)
