Class: RandomStack

Inherits:
Object
  • Object
show all
Defined in:
lib/rfile.rb

Overview

A randomizing stack

Instance Method Summary collapse

Constructor Details

#initialize(incoming) ⇒ RandomStack

incoming is an array that becomes the stack data



107
108
109
110
# File 'lib/rfile.rb', line 107

def initialize(incoming)
  incoming.compact
  @stack = incoming.sort_by { rand }.clone
end

Instance Method Details

#lengthObject

returns the number of items left in the stack



118
119
120
# File 'lib/rfile.rb', line 118

def length
  @stack.length
end

#popObject

removes the top entry from the stack and returns it.



113
114
115
# File 'lib/rfile.rb', line 113

def pop
  @stack.pop
end