Module: Koalemos::Rand::Enumerable_
- Defined in:
- lib/koalemos/rand.rb
Instance Method Summary collapse
-
#each_random(&block) ⇒ Object
Calls block once for each element in self in random order, passing that element as a parameter.
-
#map_random(&block) ⇒ Object
Invokes block once for each element of self in random order.
-
#pick ⇒ Object
Choose and return a random element of the Enumerable.
-
#shuffle ⇒ Object
Return an array of the elements in random order.
Instance Method Details
#each_random(&block) ⇒ Object
Calls block once for each element in self in random order, passing that element as a parameter.
27 28 29 |
# File 'lib/koalemos/rand.rb', line 27 def each_random(&block) shuffle.each(&block) end |
#map_random(&block) ⇒ Object
Invokes block once for each element of self in random order. Creates a new array containing the values returned by the block.
33 34 35 |
# File 'lib/koalemos/rand.rb', line 33 def map_random(&block) shuffle.map(&block) end |
#pick ⇒ Object
Choose and return a random element of the Enumerable.
[1, 2, 3, 4].pick #=> 2 (or 1, 3, 4)
15 16 17 |
# File 'lib/koalemos/rand.rb', line 15 def pick entries.pick end |
#shuffle ⇒ Object
Return an array of the elements in random order.
[1, 2, 3, 4].shuffle #=> [3, 4, 1, 2]
21 22 23 |
# File 'lib/koalemos/rand.rb', line 21 def shuffle entries.shuffle end |