Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/wrandom.rb
Instance Method Summary collapse
- #wsample(*args, &block) ⇒ Object
- #wshuffle(options = {}, &block) ⇒ Object
- #wshuffle!(options = {}, &block) ⇒ Object
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, = \ if args.size == 0 || args[0].class == Hash [nil, args[0]] else [args[0], args[1]] end arr = wshuffle(, &block) count ? arr.first(count) : arr.first end |
#wshuffle(options = {}, &block) ⇒ Object
13 14 15 |
# File 'lib/wrandom.rb', line 13 def wshuffle( = {}, &block) sort_by { |v| w_algorithm(v, , &block) }.reverse! end |
#wshuffle!(options = {}, &block) ⇒ Object
17 18 19 |
# File 'lib/wrandom.rb', line 17 def wshuffle!( = {}, &block) sort_by! { |v| w_algorithm(v, , &block) }.reverse! end |