class Quality::Which
Determine where a given executable lives, like the UNIX ‘which’ command
Public Class Methods
new(env: ENV, file: File, separator: File::PATH_SEPARATOR)
click to toggle source
# File lib/quality/which.rb, line 8 def initialize(env: ENV, file: File, separator: File::PATH_SEPARATOR) @env = env @file = file @separator = separator end
Public Instance Methods
which(cmd)
click to toggle source
# File lib/quality/which.rb, line 16 def which(cmd) exts = @env['PATHEXT'] ? @env['PATHEXT'].split(';') : [''] @env['PATH'].split(@separator).each do |path| exts.each do |ext| exe = @file.join(path, "#{cmd}#{ext}") return exe if @file.executable?(exe) && !@file.directory?(exe) end end nil end