Class: Array

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

Overview

Augments the ruby array class with a couple convenient random picking methods

Instance Method Summary collapse

Instance Method Details

#pickObject

Picks one value from the array at random, array remains unchanged.



109
110
111
# File 'lib/anonymizer.rb', line 109

def pick
  at(rand(length))
end

#pick!Object

Removes and returns one element of the array at random, the original array is changed by this method.



114
115
116
# File 'lib/anonymizer.rb', line 114

def pick!
  delete_at(rand(length))
end