Solved

Ruby Array Stack Class

Posted on 2010-11-27
3
1,027 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 250 total points
Comment Utility
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
Comment Utility
Thank you
0
 
LVL 12

Expert Comment

by:JESii
Comment Utility
You're welcome; thanks for the points!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now