Class: Which
- Inherits:
-
Object
- Object
- Which
- Defined in:
- lib/quality/which.rb
Instance Method Summary collapse
-
#which(cmd) ⇒ Object
stackoverflow.com/questions/2108727/ which-in-ruby-checking-if-program-exists-in-path-from-ruby.
Instance Method Details
#which(cmd) ⇒ Object
stackoverflow.com/questions/2108727/
which-in-ruby-checking-if-program-exists-in-path-from-ruby
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/quality/which.rb', line 4 def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each { |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) } end return nil end |