Methods

Warbler::PlatformHelper

Public Instance Methods

which(cmd) click to toggle source

Cross-platform way of finding an executable in the $PATH. Thanks to @mislav

which('ruby') #=> /usr/bin/ruby
# File lib/warbler/platform_helper.rb, line 14
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
    }
  end
  return nil
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.