Class: RandomStack
- Inherits:
-
Object
- Object
- RandomStack
- Defined in:
- lib/rfile.rb
Overview
A randomizing stack
Instance Method Summary collapse
-
#initialize(incoming) ⇒ RandomStack
constructor
incoming is an array that becomes the stack data.
-
#length ⇒ Object
returns the number of items left in the stack.
-
#pop ⇒ Object
removes the top entry from the stack and returns it.
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
#length ⇒ Object
returns the number of items left in the stack
118 119 120 |
# File 'lib/rfile.rb', line 118 def length @stack.length end |
#pop ⇒ Object
removes the top entry from the stack and returns it.
113 114 115 |
# File 'lib/rfile.rb', line 113 def pop @stack.pop end |