weighted_list 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d5b3840de4d609e646fb51214fd8ee68ffb538878213e5d3a03e59d53410f7b
4
- data.tar.gz: 6a6a085e2d086c4ae4ca00e7dacecd3350f1af2f98cd910f3c1d8a0be07c3c15
3
+ metadata.gz: edc13fc465f39a1abfc91f959e083e87ee93b548e8b116a45fcabdd5d3cc1d56
4
+ data.tar.gz: 7c1b2b087b95da2fb666d64846b4bc7b13ac4fd125b40cc64bad894ff84ec90b
5
5
  SHA512:
6
- metadata.gz: f52a7a8bdc0e912069f1ef71ce74220c24d720e71c8d3faadc328f5398127daac959a327cb1b9268e9ed9a227892a214b80816d46ef22fcfa8318e86dd1d7044
7
- data.tar.gz: d79b5c017734bb73f73392d280a0d745f50c868b2c56a3b826d69f7b93db929dd1d633a415c9bb6244ffeacb47e1016c01a881d5c889d6909805d244a01638f1
6
+ metadata.gz: 5bb74954a64d3ba853b07166368b69c7dc9c515fa170a2e07f25aaa1205eb8934bffbd71e728f9eb86b80e30bc0624828b3c40ea598c921935063ac92242df29
7
+ data.tar.gz: 276a957b420a22604a1ff4be21f72aab02c963335094271ca1a3cfc9b7a55a4c93e6bcad23deff2b0a4a1307bf8b816e6bbde3d04f52f5439d2472145f75ddf8
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weighted_list (0.7.0)
4
+ weighted_list (0.8.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class WeightedList
4
- VERSION = '0.7.0'
4
+ VERSION = '0.8.0'
5
5
  end
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.7.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: 2018-12-15 00:00:00.000000000 Z
11
+ date: 2019-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler