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 +4 -4
- data/lib/kujibiki/core_ext/array.rb +16 -2
- data/lib/kujibiki/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed10abe94a153e07c3a12398532041904fd77142
|
4
|
+
data.tar.gz: 7a62c4139e07aa83912b3301ca1dc5d9174ed860
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
4
|
-
|
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})"
|
data/lib/kujibiki/version.rb
CHANGED
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.
|
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:
|
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
|