tags:

views:

52

answers:

2

In Ruby, is there a difference between %w(x y z) and %w[x y z]?

I see both in docs and examples, and both seem to work for me.

+5  A: 

The () and [] are called delimiters, and you can use almost any non-alphanumeric character as a delimiter:

%w<x y z>
%w{x y z}
%w~x y z~
%w|x y z|

Some have different opening and closing characters (such as your two examples and my first two examples) and the rest just use the same characters at both ends.

yjerem
And of course all of that applies also to `%W`, `%q`, `%Q`, `%x` and `%r`.
Jörg W Mittag
+2  A: 

No. All such expressions in ruby support (), [], {}, <>, and any 2 non-word symbols. E.g., these are all valid:

%w/1 2 3/
%w\1 2 3\
%w!1 2 3!
%w.1 2 3.
glebm