What does %w do?

Asked 2 years ago, Updated 2 years ago, 37 views

I was looking at the FileUtils data and saw this code

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

I wonder what %w is doing here.

array ruby string

2022-09-21 15:34

1 Answers

%w(foo bar) is another way to express ["foo", "bar"].

puts (%w(foo bar))

Output : [The foo, " bar]

It is used to create an array that stores the string, and instead of a comma, it is characterized by dividing the string based on the space and not using quotation marks.


2022-09-21 15:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.