Module: Guard::BustedUtils
- Included in:
- Busted
- Defined in:
- lib/guard/busted/utils.rb
Overview
General utils for the gem
Instance Method Summary collapse
-
#which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
Instance Method Details
#which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
which('ruby') #=> /usr/bin/ruby
https://stackoverflow.com/a/5471032/4983981
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/guard/busted/utils.rb', line 10 def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) end end nil end |