1
我正在練習Ruby代碼,當我鍵入以下代碼時,出現以下錯誤。在這種情況下,我應該怎麼做?未定義的方法錯誤。我該怎麼辦?
的代碼是在這裏:
class RandomSequence
def initialize(limit,num)
@limit,@num=limit,num
end
def each
@num.times {yield(rand*@limit).floor}
end
end
i=-1
RandomSequence.new(10,4).each do |num|
i=num if i<num
end
錯誤消息我得到的是:
prog.rb:8:in block in each: undefined method floor for nil:NilClass (NoMethodError)
from prog.rb:8:in times
from prog.rb:8:in each
from prog.rb:14:in <main>
把代碼問題本身 –