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
Returns the value of attribute command.
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
17 18 19 |
# File 'lib/tty/system/which.rb', line 17 def initialize(command) @command = command end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
9 10 11 |
# File 'lib/tty/system/which.rb', line 9 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
47 48 49 |
# File 'lib/tty/system/which.rb', line 47 def default_system_path ENV['PATH'].split(File::PATH_SEPARATOR) end |
#which ⇒ String
Find an executable in the PATH
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tty/system/which.rb', line 33 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 return nil end |