Module: Nuggets::File::WhichMixin
- Included in:
- File
- Defined in:
- lib/nuggets/file/which_mixin.rb
Instance 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.
Instance 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_mixin.rb', line 37 def which(executable) return executable if executable?(executable) if path = ENV['PATH'] path.split(::File::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_mixin.rb', line 54 def which_command(commands) commands.find { |command| which(command[/\S+/]) } end |