" NoMethodError:未定义的方法' - @' for [" some-text"]:Array"在里面循环时

时间:2016-11-05 02:15:12

标签: ruby

一个意想不到的错误" NoMethodError:未定义的方法' - @' for [" some-text"]:Array"一段非常简单的代码:

t = []
times = 1
while times > 0 do
    times--

    case rand(16)+1
    when  1 then t.push("human-like")
    when  2 then t.push("amoeboid")
    when  3 then t.push("beast")
    when  4 then t.push("aerial")
    when  5 then t.push("amphibian")
    when  6 then t.push("bipedal")
    when  7 then t.push("insectoid")
    when  8 then t.push("radially symmetrical")
    when  9 then t.push("multipedal")
    when 10 then t.push("piscean")
    when 11 then t.push("reptilian")
    when 12 then t.push("humanoid")
    when 13 then t.push("cetacean")
    when 14 then t.push("botanic")
    when 15 then t.push("non-organic")
    else times += 2
    end
end

简单说明:

t = []
t.push("whatever")

...按预期工作,但while循环中的部分失败了。我无法理解为什么。有线索吗?我瞎了什么?

0 个答案:

没有答案