【问题标题】:Ruby: Array manipulation [closed]Ruby:数组操作 [关闭]
【发布时间】:2012-05-21 14:38:23
【问题描述】:
test = Array.new
test[0] = "foo"

工作正常

test[] = "foo"

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

【问题讨论】:

标签: ruby arrays


【解决方案1】:
test << "foo"

test.push("foo").

【讨论】:

    【解决方案2】:

    这种格式:

    test << "foo"
    

    将按照您的描述将元素附加到数组中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多