When to use %w[...] against a regular array? Iβm sure that you can come up with reasons just by looking at them and then typing them in and thinking about what you just did.
Use %w[...] when you have a list of individual words that you want to turn into an array. I use it when I have parameters that I want to iterate over, or commands that I know. I want to add them in the future because %w[...] makes it easy to add new elements to the array. The array definition has less visual noise.
Use a regular array of strings when you have elements that have an embedded white space that deceives %w . Use it for arrays that should contain elements that are not strings. Closing elements inside " and ' with intermediate commas causes visual noise, but also allows you to create arrays with any type of object.
So, you choose when to use this or that, when it makes the most sense to you. It is called "programmer choice."
source share