Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A template of stack APIs
Ruby
tag: abstractstack-…

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
example
lib
test
.gitignore
History.rdoc
LICENSE
Manifest.txt
README.rdoc
Rakefile

README.rdoc

abstractstack

Description

A template of “Stack” classies

Features

  • Base APIs are limited from Ruby's Array

    It has below methods for basic operation

    • push, <<

    • pop

    • bottom

    • top, peek

    • length, size

    • empty?

    • fifo_each, lilo_each

    • lifo_each, filo_each

    And you can get the below methods so easily

    • [], at

    • each

    • reverse_each

Usage

  • setup

    require 'abstractstack'
  • Simply

    class Stack < AbstractStack; end
    stack = Stack.new
    stack.push 1
    stack << 7
    stack.top    #=> 7
    stack.bottom #=> 1
    stack.peek   #=> 7
    stack.pop    #=> 7
    stack.pop    #=> 1
    stack.pop    #=> Exception(UnderFlow)
  • Size limitation

    stack = Stack.new 2
    stack.limit          #=> 2
    stack << 1 << 7
    stack << 9           #=> Exception(Overflow)
  • You can get your extended Stack class

    class LIFO < AbstractStack
      include Enumerable
    
      alias_method :each, :lifo_each
      alias_method :reverse_each, :fifo_each
      alias_method :first, :top
      alias_method :last, :bottom
    
      def at(pos)
        super pos, :top
      end
    end
    
    stack = LIFO.new
    stack << 1 << 7
    stack.map{|v|v * 2}  #=> [14, 2]
    stack[0]             #=> 7
    stack[-1]            #=> 1

Requirements

  • Ruby 1.9.2 or later

    Focusing

    • 1.9.3-p194

    • 1.9.2-p290

Installation

  • gem install abstractstack

License

The MIT X11 License

Copyright © 2012 Kenichi Kamiya

See the file LICENSE for further details.

Something went wrong with that request. Please try again.