开发者

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

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

I see both in docs and examples, and bo开发者_开发问答th seem to work for me.


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜