Solved

Ruby Array Stack Class

Posted on 2010-11-27
3
1,031 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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

735 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