weighted_list 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +4 -1
- data/lib/weighted_list.rb +8 -0
- data/lib/weighted_list/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edc13fc465f39a1abfc91f959e083e87ee93b548e8b116a45fcabdd5d3cc1d56
|
4
|
+
data.tar.gz: 7c1b2b087b95da2fb666d64846b4bc7b13ac4fd125b40cc64bad894ff84ec90b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bb74954a64d3ba853b07166368b69c7dc9c515fa170a2e07f25aaa1205eb8934bffbd71e728f9eb86b80e30bc0624828b3c40ea598c921935063ac92242df29
|
7
|
+
data.tar.gz: 276a957b420a22604a1ff4be21f72aab02c963335094271ca1a3cfc9b7a55a4c93e6bcad23deff2b0a4a1307bf8b816e6bbde3d04f52f5439d2472145f75ddf8
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -54,10 +54,13 @@ list.sample(2, random: CustomRandomizer.new) # => [:eastern, :central]
|
|
54
54
|
# If you want to allow repeats:
|
55
55
|
list.sample(4, with_replacement: true) # => [:eastern, :mountain, :eastern, :eastern]
|
56
56
|
|
57
|
-
# Shuffle the list while still respecting the weights
|
57
|
+
# Shuffle the list while still respecting the weights:
|
58
58
|
list.shuffle # => [:central, :eastern, :mountain, :pacific]
|
59
59
|
list.shuffle # => [:pacific, :eastern, :central, :mountain]
|
60
60
|
list.shuffle # => [:pacific, :central, :eastern, :mountain]
|
61
|
+
|
62
|
+
# If you want to mutate the original list:
|
63
|
+
list.shuffle!
|
61
64
|
```
|
62
65
|
|
63
66
|
## Development
|
data/lib/weighted_list.rb
CHANGED
@@ -33,6 +33,14 @@ class WeightedList
|
|
33
33
|
sample(hash.length, random: random)
|
34
34
|
end
|
35
35
|
|
36
|
+
def shuffle!(random: Random)
|
37
|
+
sample(hash.length, random: random).tap do |returned_collection|
|
38
|
+
returned_collection.each_with_object({}) do |item, replace_with|
|
39
|
+
replace_with[item] = hash[item]
|
40
|
+
end.tap { |replace_with| @hash = replace_with }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
36
44
|
private
|
37
45
|
|
38
46
|
attr_reader :hash, :random
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weighted_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jayson Virissimo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|