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>
문제 자체에 코드 삽입 –