我只是要重新開始學習Ruby和我正在寫一個簡單的程序,但我有一個錯誤undefined method 'send_for_beer' for Person:Class (NoMethodError)
下面是一個代碼:未定義的方法...類(NoMethodError)
class Person
@iq = 0
@speed = 0
@power = 0
@beauty = 0
def initialize (iq, speed, power, beauty)
@iq = iq
@speed = speed
@power = power
end
def send_for_beer
result @iq * 2 + @speed * 10 + @power * 5 + @beauty
return result
end
end
number_of_people = 3
person_array = Array.new(number_of_people, Person)
n = 0
beer_person = 0
beer_cof = 0
number_of_people.times do
............
person_array.push(Person.new(iq, speed, power, beauty))
if person_array[n].send_for_beer > beer_cof <-----here is an error
beer_cof = person_array[n].send_for_beer
beer_person = n
end
n = n+1
end