Skip to content

Instantly share code, notes, and snippets.

@luislavena
Created October 25, 2008 01:33
Show Gist options
  • Save luislavena/19659 to your computer and use it in GitHub Desktop.
Save luislavena/19659 to your computer and use it in GitHub Desktop.
module FileUtils
def which(file)
extensions = ENV['PATHEXT'].split(File::PATH_SEPARATOR) rescue []
pattern = "#{file}{#{extensions.join(',').downcase}}"
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
candidate = Dir.glob(File.join(File.expand_path(path), pattern)).first
return candidate if candidate && File.executable?(candidate)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment