module Teaspoon::Utility
Public Instance Methods
which(cmd)
click to toggle source
Cross-platform way of finding an executable in the $PATH. stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
# File lib/teaspoon/utility.rb, line 16 def which(cmd) exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""] ENV["PATH"].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = "#{path}/#{cmd}#{ext}" return exe if File.file?(exe) && File.executable?(exe) end end nil end