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

%w|a b c|

%w_a b c_

%w<a b c>

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.

···

--
Posted via http://www.ruby-forum.com/.

Hi --

···

On Sat, 22 Sep 2007, SpringFlowers AutumnMoon wrote:

%w|a b c|

%w_a b c_

%w<a b c>

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.

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

   ruby -e 'p %q abc '
   "abc"

:slight_smile:

David

--
Upcoming training from Ruby Power and Light, LLC:
   * Intro to Ruby on Rails, Edison, NJ, October 23-26
   * Advancing with Rails, Edison, NJ, November 6-9
Both taught by David A. Black.
See http://www.rubypal.com for more info!

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

···

--
Posted via http://www.ruby-forum.com/\.

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

···

On Sep 22, 4:02 am, SpringFlowers AutumnMoon <summercooln...@gmail.com> wrote:

%w|a b c|

%w_a b c_

%w<a b c>

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

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

--
Posted via http://www.ruby-forum.com/\.

David A. Black wrote:

Hi --

> %w|a b c|
>
> %w_a b c_
>
> %w<a b c>
>
> 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.

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

   ruby -e 'p %q abc '
   "abc"

:slight_smile:

I enjoy doing this:

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

···

On Sat, 22 Sep 2007, SpringFlowers AutumnMoon wrote:

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
         ^

···

--
Posted via http://www.ruby-forum.com/\.

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

···

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407