Module: Teabag::Utility

Included in:
Coverage, Drivers::PhantomjsDriver, Instrumentation
Defined in:
lib/teabag/utility.rb

Instance Method Summary collapse

Instance Method Details

#which(cmd) ⇒ String?

Examples:

which('ruby') #=> /usr/bin/ruby

Parameters:

  • cmd (String)

    the executable to find

Returns:

  • (String, nil)

    the path to the executable



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/teabag/utility.rb', line 13

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