Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

ruby - %w(数组)是什么意思?(What does %w(array) mean?)

I'm looking at the documentation for FileUtils.

(我正在查看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?

(%w是什么意思?)

Can you point me to the documentation?

(你能指点我的文件吗?)

  ask by Dane O'Connor translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

%w(foo bar) is a shortcut for ["foo", "bar"] .

(%w(foo bar)["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 .

(您可以在zenspider的quickref中找到编写文字的方法列表。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...