【发布时间】:2012-05-21 14:38:23
【问题描述】:
test = Array.new
test[0] = "foo"
工作正常
test[] = "foo"
返回错误。让数组自动生成索引的 Ruby 语法是什么?
【问题讨论】:
-
为了将来参考,我们欢迎任何有效的编程问题,前提是您已经done your research。
test = Array.new
test[0] = "foo"
工作正常
test[] = "foo"
返回错误。让数组自动生成索引的 Ruby 语法是什么?
【问题讨论】:
test << "foo"
或
test.push("foo").
【讨论】:
这种格式:
test << "foo"
将按照您的描述将元素附加到数组中。
【讨论】: