In meinem Programm bekomme ich einen Fehler, der besagt ./ruby_camping.rb:91:in` -': nil kann nicht in Fixnum (TypeError). Was Ich mag würde zu tun ist, einen Gast zur Kasse, die ich in nur geprüft Hier ist der Code-Block für die Kasse Teil.`- ': Nil kann nicht in Fixnum erzwungen werden (TypeError)
def self.check_out
puts "Welcome to checkout!"
puts $camping.current_guests
puts " Here are the current guests, who do you want to checkout?!"
puts "State plot number "
plot = gets.chomp.to_i
guest = $camping.current_guests[plot-1]
puts "State the date for your checkout (a number bigger then " + guest.arrived.to_s + "): "
# it should not be possible for a guest to checkout before she has checked in
departureDate = gets.chomp.to_i
guestStayedDays = departureDate - guest.arrived #Days the guest has stayed
while (guestStayedDays < 1) do
puts "The date for checkout is not valid. The guest checked in " + guest.arrived.to_s
puts "Please state a new date."
departureDate = gets.chomp.to_i
guestStayedDays = departureDate - guest.arrived
end
guest.departure = departureDate
guest.plot.increase(guestStayedDays) # increases the electricity meter
puts guest # prints the guest
$camping.current_guests[plot-1] = nil # emptys the plot
end
end
Wie kommt departureDate noch null ist? Dankbar für Hilfe!
Ja, Sie haben die richtige Zeile 91 Punkte an: guestStayedDays = departureDate - guest.arrived. Ihre Antwort bestätigt dann meinen Verdacht. Also muss der Wert null sein, nehme ich an? – Sebastien
Korrigieren. Aus dem angezeigten Fehler muss "guest.arrived" sein, also "nil". "guest" ist nicht "nil", weil Sie "angekommen" erfolgreich aufrufen, und "departureDate" ist nicht "nil", weil Sie erfolgreich "-" aufrufen. Es ist das Argument zu '-' (' guest.arrived' das ist das Problem.) – mikej
Vielen Dank mikej für Ihre Antworten. Ich werde versuchen zu sehen, ob ich das irgendwie lösen kann. – Sebastien