Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A template of stack APIs

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 example
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 .yardopts
Octocat-spinner-32 Gemfile
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 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.