Solved

Ruby Array Stack Class

Posted on 2010-11-27
3
1,034 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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 this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

617 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