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 Attribute Summary collapse
-
#command ⇒ Object
readonly
The command to find.
Instance Method Summary collapse
-
#default_system_path ⇒ Object
private
Find default system paths.
-
#initialize(command) ⇒ Which
constructor
Initialize a Which.
-
#which ⇒ String
Find an executable in the PATH.
Constructor Details
#initialize(command) ⇒ Which
Initialize a Which
16 17 18 |
# File 'lib/tty/system/which.rb', line 16 def initialize(command) @command = command end |
Instance Attribute Details
#command ⇒ Object (readonly)
The command to find
8 9 10 |
# File 'lib/tty/system/which.rb', line 8 def command @command end |
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
46 47 48 |
# File 'lib/tty/system/which.rb', line 46 def default_system_path ENV['PATH'].split(File::PATH_SEPARATOR) end |
#which ⇒ String
Find an executable in the PATH
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tty/system/which.rb', line 32 def which 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 nil end |