Sha256: f1b65f6481e52745b92e7a270a2d45126f00af64b34a86b485d61789349decf9

Contents?: true

Size: 696 Bytes

Versions: 4

Compression:

Stored size: 696 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
    #
    # @example
    #   which('ruby') #=> /usr/bin/ruby
    #
    # @param cmd [String] the executable to find
    # @return [String, nil] the path to the executable
    #
    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.executable?(exe)
        end
      end

      nil
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
teaspoon-0.7.7 lib/teaspoon/utility.rb
teaspoon-0.7.6 lib/teaspoon/utility.rb
teaspoon-0.7.5 lib/teaspoon/utility.rb
teaspoon-0.7.4 lib/teaspoon/utility.rb