Class: File
Overview
–
#
A component of ruby-nuggets, some extensions to the Ruby programming # language. #
#
Copyright © 2007-2008 Jens Wille #
#
Authors: #
Jens Wille <jens.wille@uni-koeln.de> #
#
ruby-nuggets is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 3 of the License, or (at your option) # any later version. #
#
ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. #
#
You should have received a copy of the GNU General Public License along # with ruby-nuggets. If not, see <www.gnu.org/licenses/>. #
#
++
Class Method Summary collapse
-
.which(executable) ⇒ Object
call-seq: File.which(executable) => aString or nil.
-
.which_command(commands) ⇒ Object
call-seq: File.which_command(commands) => aString or nil.
Class Method Details
.which(executable) ⇒ Object
call-seq:
File.which(executable) => aString or nil
Returns the full path to executable, or nil if not found in PATH. Inspired by Gnuplot.which – thx, Gordon!
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/nuggets/file/which.rb', line 37 def which(executable) return executable if executable?(executable) if path = ENV['PATH'] path.split(PATH_SEPARATOR).each { |dir| candidate = join(dir, executable) return candidate if executable?(candidate) } end nil end |
.which_command(commands) ⇒ Object
call-seq:
File.which_command(commands) => aString or nil
Returns the first of commands that is executable.
54 55 56 |
# File 'lib/nuggets/file/which.rb', line 54 def which_command(commands) commands.find { |command| which(command[/\S+/]) } end |