module Acouchi class Which def self.find_executable *aliases if executable = aliases.find {|a| which? a} executable else raise %{Couldn't find any matches for the aliases "#{aliases.join(", ")}"} end end private def self.which? command exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each { |ext| exe = "#{path}/#{command}#{ext}" return exe if File.executable? exe } end return nil end end end