Module: IOSIconGenerator::Library
- Defined in:
- lib/ios_icon_generator/helpers/which.rb
Class Method Summary collapse
-
.which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
Class Method Details
.which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
From stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
Parameters:
cmd-
The name of the command to search the path for.
Returns:
The full path to the command if found, and nil otherwise.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ios_icon_generator/helpers/which.rb', line 30 def self.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 |