Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 984275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:59:22+00:00 2026-05-16T04:59:22+00:00

Im trying to add objects to an array by using push. I have a

  • 0

Im trying to add objects to an array by using push. I have a program where u can register guests. When I choose the checkin option from my menu Im unable to add the new guest to the guest history.

This dont work:

def self.check_in
    puts "Welcome to the checkin"
    puts "Please state your first name: "
    firstName = gets.chomp
    puts "Please state your last name:"
    lastName = gets.chomp
    puts "Write your address: "
    address = gets.chomp
    puts "and your phone number: "
    phone = gets.chomp
    puts "finally, your arrival date!"
    arrived = gets.chomp

        newPLot = $camping.generateParkingLot
        guest = Guest.new(firstName, lastName, address, phone, arrived)
        $camping.current_guests[newPLot-1] = guest

        puts "The registration was a success!! You have received plot " + newPLot.to_s + "."
        @all_guests.push(guest)   # adds the guest to the history 
  end 

Here I get a check_in': undefined methodpush’ for nil:NilClass (NoMethodError). But if I comment out this line:

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

Im able to register a guest. An then when I choose the 3 option from my menu which is:

def self.do_action(action)
 # utför händelse baserat på valet
  case action
     when 1:
        check_in
     when 2:
        check_out
     when 3:
       puts $camping.current_guests
      when 4:
       puts $camping.all_guests
      when 5:
       puts "You are now leaving the camping, welcome back!"
       exit    
     end
  end

Then I see the guest there. The only problem is that I cant do the 4 option which is to show all guests because I have commented out that line of code. So to round things up how can I use this line of code:

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

Without receiving the error message?? Thankful for all help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:59:23+00:00Added an answer on May 16, 2026 at 4:59 am

    @all_guests isn’t defined in the file where you get the error, it’s defined in the $camping global. Change the code to

    $camping.all_guests.push(...)
    

    and see if that works better for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add a set of objects that have been retrieved from a
I have an array of objects that I'm trying to add to the Items
I have a NSMutableArray of QuoteMap objects. When I add one using the below
I'm trying to make an array of objects (animalImages) from a plist file which
I'm trying to add objects to NSMutableArray (categoriasArray), but its not done by the
I am trying to add an attirubute to objects that i created.Here i created
Trying to add a class object into a List using reflection, but when invoking
I'm trying to add results from an object to newly created HTML elements: *long
I'm trying to add a region using Azure Datacache object but I'm getting such
I have been trying to add to the Watch window a Java Date object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.