rubyhelper 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubyhelper/arrayhelper.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7bb48684d6cf895a4d869e648b11f8b00d75031
|
4
|
+
data.tar.gz: 08c7a167d218bb725b93bb4d4839eb7f7c9b3ca2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 962815fe6f04a5ed6c00fa037427dcbc94c7e390abcb10462547b4976349a04fb86b621d953984939bf288d7b236a406410dec3be8a113e7de59fad4d3a13c25
|
7
|
+
data.tar.gz: 39f04960e8b11223d24c0249a2a6e9ea904b4fac4a4ce2b3dbe6f16da7f04ee2d1ea90b6480d946abe116b282c21cd8352672f22e9df54bd81d2b159bca7ff2f
|
@@ -5,6 +5,8 @@ module ArrayHelper
|
|
5
5
|
# This function return a pretty good string. Like join but with an array
|
6
6
|
# You can use an array as separator : [",", " "] will successively ',' and ' '
|
7
7
|
# Exemple : ["a", "b", "c"].joini(["x", "y"]) => "axbyc"
|
8
|
+
# == Errors
|
9
|
+
# ArgumentError : if sep in not an array
|
8
10
|
# == Params
|
9
11
|
# sep: (Array) array of separator
|
10
12
|
# == Returns
|
@@ -43,18 +45,26 @@ module ArrayHelper
|
|
43
45
|
end
|
44
46
|
|
45
47
|
# get the n higher values of the array
|
48
|
+
# == Errors
|
49
|
+
# ArgumentError : if n in not an integer
|
46
50
|
# == Params
|
47
51
|
# n: (Integer) number of elements
|
48
52
|
def maxs(n=1)
|
53
|
+
raise ArgumentError, 'Argument is not an integer' unless n.is_a? Integer
|
49
54
|
n = 1 if n < 1
|
50
55
|
n = self.size if n > self.size
|
51
56
|
return Array(self.sort[(-n)..(-1)])
|
52
57
|
end
|
53
58
|
|
54
59
|
# get the n lower values of the array
|
60
|
+
# == Errors
|
61
|
+
# ArgumentError : if n in not an integer
|
55
62
|
# == Params
|
56
63
|
# n: (Integer) number of elements
|
57
64
|
def mins(n=1)
|
65
|
+
raise ArgumentError, 'Argument is not an integer' unless n.is_a? Integer
|
66
|
+
n = 1 if n < 1
|
67
|
+
n = self.size if n > self.size
|
58
68
|
return Array(self.sort[0..(n-1)])
|
59
69
|
end
|
60
70
|
|