Sha256: 79672c913c92d71a5a099f147c21c2ce5578a1c84876caf3d02e34d07e3eb296
Contents?: true
Size: 562 Bytes
Versions: 2
Compression:
Stored size: 562 Bytes
Contents
class FindExecutable < Struct.new(:executable) def self.call(*args) new(*args).call end def call which(executable) end private # Cross-platform way of finding an executable in the $PATH. # # which('ruby') #=> /usr/bin/ruby def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each { |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) } end nil end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
imuzer-0.0.4 | lib/find_executable.rb |
imuzer-0.0.3 | lib/find_executable.rb |