kujibiki 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0baf99db6191159260aaeceba7edd02fd7441b77
4
- data.tar.gz: 14ada7b149034609388758a7e4e77393c8c39d2a
3
+ metadata.gz: ed10abe94a153e07c3a12398532041904fd77142
4
+ data.tar.gz: 7a62c4139e07aa83912b3301ca1dc5d9174ed860
5
5
  SHA512:
6
- metadata.gz: 4b9a1e58e234cd2e7d730b6b8ce5ee21e08a42dbdc83d81abcc0375e87d2aa8b0ff32e8befe3168962ddf15f0ae90226361e13a49465406e1360970026a53cae
7
- data.tar.gz: 92890a95bd72140405bdbbab6439f7ada412d68b59941c3d9a75a5ac4e1ea872eaca415b2ca91af2cd470f3ee4769fad13b23e65ac061c4b5b3f50d19505a821
6
+ metadata.gz: ac3d8ed93d3bfe374a9d71eee40076bd413d16bb7e93daefdd937144a6f0f79f932fa07c6539a832d5f0bc88d6f1ac0be4c43af7d6d9a151d422586b0be5e2ca
7
+ data.tar.gz: 992d2f60c1a85572d51af35e53c7ec61a0df7f5229668158d84b7261b6d49fb8a448b7b7033749ae720e1997a9c3732d7a0e2feb4ebd4827d5a78372434688af
@@ -1,7 +1,21 @@
1
1
  class Array
2
2
  alias_method :_sample, :sample
3
- def sample(n = 1, random: nil, weight: nil)
4
- return _sample(n, random: random) unless weight
3
+ def sample(n=nil, random: nil, weight: nil)
4
+ unless weight
5
+ if n
6
+ if random
7
+ return _sample(n, random: random)
8
+ else
9
+ return _sample(n)
10
+ end
11
+ else
12
+ if random
13
+ return _sample(random: random)
14
+ else
15
+ return _sample
16
+ end
17
+ end
18
+ end
5
19
 
6
20
  unless weight.select {|w| w > 0}.size >= n
7
21
  raise ArgumentError, "weight size must be larger than or equal to sample number(#{n})"
@@ -1,3 +1,3 @@
1
1
  module Kujibiki
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kujibiki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoki Shimizu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-27 00:00:00.000000000 Z
11
+ date: 2016-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubyforge_project:
96
- rubygems_version: 2.4.5
96
+ rubygems_version: 2.4.5.1
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: Allow Array#sample to return waighted results