Sha256: e5dd380a30cd2842fa103faf3e57f0c5d4826b03b67505d0bb201c0e3772e095
Contents?: true
Size: 766 Bytes
Versions: 50
Compression:
Stored size: 766 Bytes
Contents
# frozen_string_literal: true # http://stackoverflow.com/questions/2108727/ # which-in-ruby-checking-if-program-exists-in-path-from-ruby module Quality # Determine where a given executable lives, like the UNIX 'which' command class Which def initialize(env: ENV, file: File, separator: File::PATH_SEPARATOR) @env = env @file = file @separator = separator end 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 end end
Version data entries
50 entries across 50 versions & 1 rubygems