Class: Array

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

Instance Method Summary collapse

Instance Method Details

#wsample(*args, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/wrandom.rb', line 2

def wsample(*args, &block)
  count, options = \
    if args.size == 0 || args[0].class == Hash
      [nil, args[0]]
    else
      [args[0], args[1]]
    end
  arr = wshuffle(options, &block)
  count ? arr.first(count) : arr.first
end

#wshuffle(options = {}, &block) ⇒ Object



13
14
15
# File 'lib/wrandom.rb', line 13

def wshuffle(options = {}, &block)
  sort_by { |v| w_algorithm(v, options, &block) }.reverse!
end

#wshuffle!(options = {}, &block) ⇒ Object



17
18
19
# File 'lib/wrandom.rb', line 17

def wshuffle!(options = {}, &block)
  sort_by! { |v| w_algorithm(v, options, &block) }.reverse!
end