-7
test = Array.new
test[0] = "foo"

工作正常

test[] = "foo"

返回错误。让数组自动生成索引的 Ruby 语法是什么?

4

2 回答 2

5
test << "foo"

or

test.push("foo").
于 2012-05-21T14:40:46.017 回答
3

This format:

test << "foo"

will append an element to an array as you're describing.

于 2012-05-21T14:40:26.633 回答