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 8310755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:34:30+00:00 2026-06-08T19:34:30+00:00

Working toward making a small command line script in Ruby, where the user provides

  • 0

Working toward making a small command line script in Ruby, where the
user provides a few pieces of information related to restaurants, and
computed info gets returned.

Currently I have the following code:

class Restaurant
 attr_accessor :name :type :avg_price
 def initialize(name, type, avg_price)
   @name = name
   @type = type
   @avg_price = price
 end
 end

Question 1

If we used attr_accessors method to declare type, and price, and name
Why is the Initialize method necessary? Is this because we need to set the
inputed values to it?

Question 2

There is a sub-class called RestaurantList followed by < Array in the code. What is the function of this?

The Array class is not defined in the code? Is it a built in class in ruby called Array? If so, what exactly does it do?

  • 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-06-08T19:34:33+00:00Added an answer on June 8, 2026 at 7:34 pm

    Question 1

    The attr_accessor method is a short cut to declaring variable accessible outside the
    block within the method.

    The initializer method in ruby is the method to be called when someone initializes
    something of that class, i.e. chipotle = Restaurant.new 'Chipotle', 'Mexican', 8.00

    Question 2

    Array is indeed a class built into Ruby, (built in classes generally referred to as the Ruby Standard Library, see here for the MRI 1.9.3 documentation on the Array class. You do not need to do any kind of special inheritance in order the use the Array class though. The language is defined in a manor such that things such as string, hashes, arrays, and other commonly used classes do not need to be inherited.

    That said, these are able to be overloaded. Don’t be surprised the day you find something that looks like an array but has alternate functionality.

    Other Notes

    One thing to keep in mind when you approach Ruby programming is that everything is an object. You will often hear this but it difficult to comprehend when you first dive but still important to keep in mind that everything can be mapped back to the Object class in Ruby, see here for documentation on the Object class.

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

Sidebar

Related Questions

I am working toward a small webapp that I would like to have a
These past few days I've been working toward converting my PHP code base from
Working on a small game using an HTML5 canvas, and javascript. And it's working
Working with MS Access for the first time and coming across a few problems
I am working on an Android app that has multiple screens the user will
so I'm working on a basic notepad program designed to be helpful toward web
I am further toward getting this SSL connection working but if someone could tell
In a previous question about overriding Time.now , I was working toward a solution
I'm working from the XunitContrib codeplex page and toward the bottom it lists these
I'm working on a small webapp in Rails that simulates a score card for

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.