arrays - undefined method `push' for nil:NilClass (NoMethodError) Ruby -


I am trying to add an object using push, and I have a program where you register guests When I select the checkin option from my menu, Im is unable to add a new guest to the guest's history.

Do not do this:

  def puts self.check_in "Welcome to checkin" puts "Please specify your first name:" firstName = gets.chomp "Please state your last name:" last name = puts gets.chomp "Enter your address:" address = gets.chomp puts "and your phone number:" phone = gets.chomp puts "Finally, your date of arrival! "Arrived = get.chomp newplot = $ camping.generateParkingLot Guest = Guest New (first name, last name, address, phone, arrived) $ camping.current_guests [newPLot-1] = Guests say "Registration was successful !! You've got conspiracy" + newPLot.to_s + "." @All_guests Push (Guest) connects guest to end of history  

Here I get a check_in ': Undefined method push for zero: NilClass (NoMethodError ). But if I comment on this line:

  # @ all_guests.push adds # guest to history  

I am able to register. One, when I select 3 options from my menu:

  def self.do_action (action) #countable case action when the 1: check_in when 2: check_out when 3: puts $ Camping.current_guests 4: puts $ camping.all_guests when 5: Say, "Now you are leaving the camp, welcome back!" End of exit end  

Then I see guests there. The only problem is that I can not make 4 choices for all the guests because I have commented on the line of that code. So how can I use the code of this line to fulfill things:

@ all_guests.push (guest) #adds the guest to history

get error message without ?? Thanks for all the help!

@all_guests is not defined in the file, where you get the error, It is defined in the $ camp global

  $ camping.all_guests.push (...)  

And see if it works better for you.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -