# Short hand %w

**URL:** <https://www.ruby-forum.com/t/short-hand-w/94655>\
**Category:** Ruby\
**Created:** [May 10, 2006, 6:15am UTC](https://www.ruby-forum.com/t/short-hand-w/94655 "2006-05-10T06:15:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![corey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/838e76/32.png) [@corey](https://www.ruby-forum.com/u/corey)\
**Post date:** [May 10, 2006, 6:15am UTC](https://www.ruby-forum.com/t/short-hand-w/94655/1 "2006-05-10T06:15:09Z")

</div>

how come when i do this m = %w[cat [dog dog] mouse] and then request  
m[1] instead of giving me [“dog”, “dog”] it gives me “[dog”

do i have to use the shorthand %w for the inner array too?

---

<div class="post-metadata">

**Author:** ![corey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/838e76/32.png) [@corey](https://www.ruby-forum.com/u/corey)\
**Post date:** [May 10, 2006, 6:19am UTC](https://www.ruby-forum.com/t/short-hand-w/94655/2 "2006-05-10T06:19:06Z")

</div>

Corey wrote:

> how come when i do this m = %w[cat [dog dog] mouse] and then request  
> m[1] instead of giving me [“dog”, “dog”] it gives me “[dog”
> 
> do i have to use the shorthand %w for the inner array too?

i tride it on the inner array and it return %w"[dog" so that doesnt  
work, the %w doesnt seem to work accros the board the way i thought it  
would.

---

<div class="post-metadata">

**Author:** ![corey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/838e76/32.png) [@corey](https://www.ruby-forum.com/u/corey)\
**Post date:** [May 10, 2006, 6:29am UTC](https://www.ruby-forum.com/t/short-hand-w/94655/3 "2006-05-10T06:29:50Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Corey wrote:

> Corey wrote:
> 
> > how come when i do this m = %w[cat [dog dog] mouse] and then request  
> > m[1] instead of giving me [“dog”, “dog”] it gives me “[dog”
> > 
> > do i have to use the shorthand %w for the inner array too?
> 
> i tride it on the inner array and it return %w"[dog" so that doesnt  
> work, the %w doesnt seem to work accros the board the way i thought it  
> would.

As mentioned a few weeks ago on this list, you must escape  
whitespace within a single “word” using backslashes (a convention of  
UNIX shells, AFAIK):

irb(main):003:0\> %w(cat dog\ dog mouse)  
=\> [“cat”, “dog dog”, “mouse”]

irb(main):004:0\> %w(cat dog\ dog mouse this\ is\ \ \ a\ long\ phrase)  
=\> [“cat”, “dog dog”, “mouse”, “this is a long phrase”]  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFEYWuamV9O7RYnKMcRAtEuAJ960nSEOXSqhVVATiCkkMeSOzD80ACeI8NI  
cX5/sgIC+1KaCjYe3NTH5Gs=  
=bbpe  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![corey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/838e76/32.png) [@corey](https://www.ruby-forum.com/u/corey)\
**Post date:** [May 10, 2006, 8:01am UTC](https://www.ruby-forum.com/t/short-hand-w/94655/4 "2006-05-10T08:01:14Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Corey wrote:

> oh ok thanks i am new to programming and have only been around this  
> forum for about 3 days now.

Ah, I was trying to give you a hint about ruby-talk archives:  
[http://www.ruby-talk.org](http://www.ruby-talk.org). There you can find every discussion that  
was ever occurred on the ruby-talk mailing list.

Happy hunting. 🙂  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFEYYFqmV9O7RYnKMcRAu1TAKCDdHYwQ/C+O4ByNklcwH3Y4EE//wCgoV6i  
I+j8YuVnk9eIGCzP7LivROc=  
=McCI  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![corey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/838e76/32.png) [@corey](https://www.ruby-forum.com/u/corey)\
**Post date:** [May 10, 2006, 6:33am UTC](https://www.ruby-forum.com/t/short-hand-w/94655/5 "2006-05-10T06:33:42Z")

</div>

> As mentioned a few weeks ago on this list, you must escape  
> whitespace within a single “word” using backslashes (a convention of  
> UNIX shells, AFAIK):

oh ok thanks i am new to programming and have only been around this  
forum for about 3 days now.
