Short hand %w


#1

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?


#2

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.


#3

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


#4

-----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. There you can find every discussion that
was ever occurred on the ruby-talk mailing list.

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

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


#5

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.