新手问题 有关 Array.new 的问题

vowxie · September 22, 2015 · Last by vowxie replied at September 22, 2015 · 1156 hits

因为想练习列表的一些操作,所以随手在 Google 上搜索了随机生成数字数组的方法

找到了一行代码,想不通为什么可以这么写

Array.new(20){rand(30)} 

In the last form, an array of the given size is created. Each element in this array is created by passing the element’s index to the given block and storing the return value.

http://ruby-doc.org/core-2.2.0/Array.html#method-c-new

#1 楼 @rei 多谢,我指的是我完全没想到查文档。

You need to Sign in before reply, if you don't have an account, please Sign up first.