Class: TTY::System::Which
- Inherits:
-
Object
- Object
- TTY::System::Which
- Defined in:
- lib/tty/system/which.rb
Overview
A class responsible for finding an executable in the PATH
Instance Method Summary collapse
-
#default_system_path ⇒ Object
private
Find default system paths.
-
#which(command) ⇒ String
Find an executable in the PATH.
Instance Method Details
#default_system_path ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Find default system paths
35 36 37 |
# File 'lib/tty/system/which.rb', line 35 def default_system_path ENV['PATH'].split(File::PATH_SEPARATOR) end |
#which(command) ⇒ String
Find an executable in the PATH
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tty/system/which.rb', line 21 def which(command) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] default_system_path.each do |path| exts.each do |ext| exec = File.join("#{path}", "#{command}#{ext}") return exec if File.executable? exec end end return nil end |