Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Ruby Array Stack Class

Posted on 2010-11-27
3
Medium Priority
?
1,040 Views
Last Modified: 2012-05-10

my assignment is to implement a stack class (based on Array) using push, pop, length and empty.

Also, to provide example test code which makes use of the stack.  
Have I satisfied this?  At line 21 would be the example code?  or is this part of my stack?

Thanks for looking, my professor expects us to pick up Ruby in one week and won't answer questions over the Holiday.
0
Comment
Question by:aflamin2424
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
JESii earned 1000 total points
ID: 34223894
Seems to work fine for me; yes, line 21 on is your test code.

It's always a good thing to test some of the boundary conditions, like what happens when you try to pop from an empty stack... I added this to your test code at the end, when the stack was empty.

If you can think of other error or boundary conditions, you can add those to your test suite as well.


test = stack.pop
puts "Result from empty stack: " +( test.nil? ? "nil" : test)
puts stack.length

Open in new window

0
 

Author Closing Comment

by:aflamin2424
ID: 34227731
Thank you
0
 
LVL 12

Expert Comment

by:JESii
ID: 34227922
You're welcome; thanks for the points!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question