The difference from %w to %W in Ruby

Difference between %w and %W

In short, %w act as ', while %W act as "
In long words, %w not convert the #{} clause, but %W do, like the codes below:

Code

irb(main):001:0> foo="hello"
=> "hello"
irb(main):002:0> %W(foo bar baz #{foo})
=> ["foo", "bar", "baz", "hello"]
irb(main):003:0> %w(foo bar baz #{foo})
=> ["foo", "bar", "baz", "\#{foo}"]

Reference

http://stackoverflow.com/questions/690794/ruby-arrays-w-vs-w

发表评论

电子邮件地址不会被公开。 必填项已用*标注