Sunday, May 6, 2018

ruby - What does %w(array) mean?



I'm looking at the documentation for FileUtils. I'm confused by the following line:



FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6'



What does the %w mean? Can you point me to the documentation?


Answer



%w(foo bar) is a shortcut for ["foo", "bar"]. Meaning it's a notation to write an array of strings separated by spaces instead of commas and without quotes around them. You can find a list of ways of writing literals in zenspider's quickref.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...