Stackable

Stackable mixin provides pop, push, pull, etc. It depends on slice, splice and insert.

Methods
Public Instance methods
peek()

Peek at the top of the stack.

  a = [1, 2, 3]
  a.peek          #=> 3
  a               #=> [1, 2, 3]
# File lib/facets/stackable.rb, line 81
  def peek
    slice(-1)
  end
poke(x)

Poke item onto the stack.

  a = [2, 3]
  a.poke(1)       #=> [1, 2, 3]

  TODO: Better name (besides unshift)?
This method is also aliased as unshift
# File lib/facets/stackable.rb, line 69
  def poke(x)
    insert(0,x)
  end
pop()

Pop item off stack.

  a = [1, 2, 3]
  a.pop           #=> 3
  a               #=> [1, 2]
# File lib/facets/stackable.rb, line 37
  def pop
    splice(-1)
  end
pull()

Pull item off the stack.

  a = [1, 2, 3]
  a.pull          #=> 1
  a               #=> [2, 3]
This method is also aliased as shift
# File lib/facets/stackable.rb, line 56
  def pull
    slice(0)
  end
push(x)

Push item onto the stack.

  a = [1, 2]
  a.push(3)       #=> [1, 2, 3]
# File lib/facets/stackable.rb, line 46
  def push(x)
    insert(-1,x)
  end
shift()

Alias for pull

unshift(x)

Alias for poke