darkhelmet-darkext 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/darkext/array.rb +6 -0
- data/lib/darkext/string.rb +9 -2
- metadata +1 -1
data/lib/darkext/array.rb
CHANGED
@@ -29,6 +29,11 @@ class Array
|
|
29
29
|
self.map(&:square)
|
30
30
|
end
|
31
31
|
|
32
|
+
# Destructively collects the squares
|
33
|
+
def squares!
|
34
|
+
self.map!(&:square)
|
35
|
+
end
|
36
|
+
|
32
37
|
# Finds the sum of squares of the array
|
33
38
|
def sum_of_squares
|
34
39
|
self.squares.sum
|
@@ -38,6 +43,7 @@ class Array
|
|
38
43
|
def random
|
39
44
|
self[rand(self.size)]
|
40
45
|
end
|
46
|
+
alias :pick :random
|
41
47
|
|
42
48
|
# Randomizes the array
|
43
49
|
def randomize
|
data/lib/darkext/string.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'darkext/hash'
|
2
|
+
|
1
3
|
class String
|
2
4
|
# Parses a string like "1..10" to a Range
|
3
5
|
def to_range
|
@@ -13,7 +15,12 @@ class String
|
|
13
15
|
end
|
14
16
|
|
15
17
|
# Executes the string with system
|
16
|
-
def exec
|
17
|
-
|
18
|
+
def exec(opts = {})
|
19
|
+
opts.with_defaults!(:background => false)
|
20
|
+
cmd = self
|
21
|
+
cmd += " &" if opts[:background]
|
22
|
+
system(cmd)
|
18
23
|
end
|
24
|
+
|
25
|
+
alias :/ :split
|
19
26
|
end
|