ruby-nuggets 0.0.6.189 → 0.0.7.194

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to ruby-nuggets version 0.0.6
5
+ This documentation refers to ruby-nuggets version 0.0.7
6
6
 
7
7
 
8
8
  == DESCRIPTION
data/lib/nuggets/all.rb CHANGED
@@ -25,6 +25,6 @@
25
25
  ###############################################################################
26
26
  #++
27
27
 
28
- Dir[File.dirname(__FILE__) + '/**/*.rb'].sort.each { |rb|
28
+ Dir[File.dirname(__FILE__) + '/*/**/*.rb'].sort.each { |rb|
29
29
  require rb
30
30
  }
@@ -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
- inject([]) { |flat, element|
36
- case element
37
- when Array
38
- flat + element
39
- else
40
- flat << element
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
@@ -4,7 +4,7 @@ module Nuggets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 0
7
- TINY = 6
7
+ TINY = 7
8
8
 
9
9
  class << self
10
10
 
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.6.189
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-25 00:00:00 +01:00
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