ruby-nuggets 0.0.6.189 → 0.0.7.194
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.
- data/README +1 -1
- data/lib/nuggets/all.rb +1 -1
- data/lib/nuggets/array/flatten_once.rb +11 -7
- data/lib/nuggets/file/which.rb +74 -0
- data/lib/nuggets/version.rb +1 -1
- metadata +4 -3
data/README
CHANGED
data/lib/nuggets/all.rb
CHANGED
@@ -30,16 +30,20 @@ class Array
|
|
30
30
|
# call-seq:
|
31
31
|
# array.flatten_once => new_array
|
32
32
|
#
|
33
|
-
# Flatten _array_ by _one_ level only.
|
33
|
+
# Flatten _array_ by _one_ level only. Pretty straight-forward port of David
|
34
|
+
# Alan Black's flattenx C implementation (though much slower, of course ;-).
|
34
35
|
def flatten_once
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
flat = []
|
37
|
+
|
38
|
+
each { |element|
|
39
|
+
if element.is_a?(Array)
|
40
|
+
flat + element
|
41
|
+
else
|
42
|
+
flat << element
|
41
43
|
end
|
42
44
|
}
|
45
|
+
|
46
|
+
flat
|
43
47
|
end
|
44
48
|
|
45
49
|
# call-seq:
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# A component of ruby-nuggets, some extensions to the Ruby programming #
|
5
|
+
# language. #
|
6
|
+
# #
|
7
|
+
# Copyright (C) 2007-2008 Jens Wille #
|
8
|
+
# #
|
9
|
+
# Authors: #
|
10
|
+
# Jens Wille <jens.wille@uni-koeln.de> #
|
11
|
+
# #
|
12
|
+
# ruby-nuggets is free software; you can redistribute it and/or modify it #
|
13
|
+
# under the terms of the GNU General Public License as published by the Free #
|
14
|
+
# Software Foundation; either version 3 of the License, or (at your option) #
|
15
|
+
# any later version. #
|
16
|
+
# #
|
17
|
+
# ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
|
18
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
20
|
+
# more details. #
|
21
|
+
# #
|
22
|
+
# You should have received a copy of the GNU General Public License along #
|
23
|
+
# with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
|
24
|
+
# #
|
25
|
+
###############################################################################
|
26
|
+
#++
|
27
|
+
|
28
|
+
class File
|
29
|
+
|
30
|
+
class << self
|
31
|
+
|
32
|
+
# call-seq:
|
33
|
+
# File.which(executable) => aString or nil
|
34
|
+
#
|
35
|
+
# Returns the full path to +executable+, or +nil+ if not found in PATH.
|
36
|
+
# Inspired by Gnuplot.which -- thx, Gordon!
|
37
|
+
def which(executable)
|
38
|
+
return executable if executable?(executable)
|
39
|
+
|
40
|
+
if path = ENV['PATH']
|
41
|
+
path.split(PATH_SEPARATOR).each { |dir|
|
42
|
+
candidate = join(dir, executable)
|
43
|
+
return candidate if executable?(candidate)
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
return nil
|
48
|
+
end
|
49
|
+
|
50
|
+
# call-seq:
|
51
|
+
# File.which_command(commands) => aString or nil
|
52
|
+
#
|
53
|
+
# Returns the first of +commands+ that is executable.
|
54
|
+
def which_command(commands)
|
55
|
+
commands.find { |command| which(command[/\S+/]) }
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
if $0 == __FILE__
|
63
|
+
%w[cat dog rat gcc /usr/bin/X11/gcc].each { |e|
|
64
|
+
p [e, File.which(e)]
|
65
|
+
}
|
66
|
+
|
67
|
+
c = [
|
68
|
+
'unison --args source target',
|
69
|
+
'rsync --args source target',
|
70
|
+
'scp --args source target'
|
71
|
+
]
|
72
|
+
p c
|
73
|
+
p File.which_command(c)
|
74
|
+
end
|
data/lib/nuggets/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-nuggets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7.194
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Wille
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-01
|
12
|
+
date: 2008-02-01 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -20,9 +20,9 @@ executables: []
|
|
20
20
|
extensions: []
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
|
-
- README
|
24
23
|
- COPYING
|
25
24
|
- ChangeLog
|
25
|
+
- README
|
26
26
|
files:
|
27
27
|
- lib/nuggets/integer/factorial.rb
|
28
28
|
- lib/nuggets/version.rb
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/nuggets/array/combination.rb
|
48
48
|
- lib/nuggets/util/content_type.rb
|
49
49
|
- lib/nuggets/util/i18n.rb
|
50
|
+
- lib/nuggets/file/which.rb
|
50
51
|
- lib/nuggets/uri/content_type.rb
|
51
52
|
- lib/nuggets/uri/exist.rb
|
52
53
|
- COPYING
|