Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A template of stack APIs
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
example
lib
test
.gitignore
.travis.yml
.yardopts
Gemfile
MIT-LICENSE
README.md
Rakefile
abstractstack.gemspec

README.md

abstractstack

Description

A template of stack APIs

Features

For basic operations.

  • push, <<
  • pop
  • bottom
  • top, peek
  • length, size
  • empty?
  • fifo_each, lilo_each
  • lifo_each, filo_each

Easy to get.

  • [], at
  • each
  • reverse_each

Others

  • Pure Ruby :)

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 Limit

stack = Stack.new 2
stack.limit          #=> 2
stack << 1 << 7
stack << 9           #=> Exception(Overflow)

Enhanced Stack class

class LIFO < AbstractStack
  include Enumerable
  include Subscriptable

  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

Build Status

Build Status

Install

$ gem install abstractstack

Link

License

The MIT X11 License
Copyright (c) 2012 Kenichi Kamiya
See MIT-LICENSE for further details.

Something went wrong with that request. Please try again.