开发者

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

开发者 https://www.devze.com 2023-01-22 21:56 出处:网络
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 almos

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

精彩评论

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

关注公众号