Sha256: 2bfafe9c89c106c498633993f480fac79815a5cce81a8a71c7cbfa4f152963f3

Contents?: true

Size: 531 Bytes

Versions: 2

Compression:

Stored size: 531 Bytes

Contents

module Teaspoon
  module Utility
    # Cross-platform way of finding an executable in the $PATH.
    # http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
teaspoon-0.9.1 lib/teaspoon/utility.rb
teaspoon-0.9.0 lib/teaspoon/utility.rb