Кто-нибудь знает, почему я получаю эту ошибку: initialize': undefined method
gauge 'для # (NoMethodError) ?!Я имею в виду, что я использую attr_accessor для геттеров и сеттеров для манометров, но все же он говорит, что я не объявил это.Ниже я разместил фрагмент кода.Заранее спасибо.
class ParkingLotGuest < Guest
attr_accessor :gauge, :electricity_bill, :type_of_stay
def initialize (name, address, phone, arrival, lives_where, type_of_stay, guest_wishes_electricity)
super(name, address, phone, arrival, lives_where)
@type_of_stay = type_of_stay
@electricity_bill = 0
@gauge = 0;
if (guest_wishes_electricity[0,1] == "j")
@gauge = lives_where.gauge
end
end
Вот код формы класса parking_lot:
class Parking_Lot
attr_accessor :nr
attr_accessor :gauge
attr_reader :electricity_meter
# Initiates a new caravan plot with the number nr and a electricity meter between
# 2000 och 4000.
def initialize (nr)
@nr = nr
@gauge = gauge
@electricity_meter = 4000-rand(2000)
end
# increases the electricity meter for use with a random amount between
# 10-80 kWh per 24 h.
def increase_meter(days)
generatedUse = (10+rand(70))*days
puts "Increases the meter with " + generatedUse.to_s + " kWh."
@electricity_meter += generatedUse
end
# Returns a string representation of the camping plot.
def to_s
"Plot #{@nr+1} Electricity meter: #{@electricity_meter} kWh"
end
end
Код из класса кемпинга.
@staticGuests = Array[
ParkingLotGuest.new("Logan Howlett", "Tokyo", "07484822", 1, @parking_lots[0], "Husvagn", "j", @gauge),
ParkingLotGuest.new("Scott Summers", "Chicago", "8908332", 2, @parking_lots[1], "Husbil", "j", @gauge),
ParkingLotGuest.new("Hank Moody", "Boston", "908490590",23, @parking_lots[2], "Tält", "n", @gauge),
CabinGuest.new("Jean Grey", "Detroit", "48058221", 4, @parking_lots[3]['Wolverine']),
CabinGuest.new("Charles Xavier", "Washington DC", "019204822", 5, @parking_lots[4]['Thanos'])
]