Sha256: 13acbd2cc427cce22e7b5616d1fce6a4dc025d853024c13475f8d4f3bb2da615

Contents?: true

Size: 693 Bytes

Versions: 1

Compression:

Stored size: 693 Bytes

Contents

module Teabag
  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

1 entries across 1 versions & 1 rubygems

Version Path
teabag-0.5.5 lib/teabag/utility.rb