title: "which in ruby": Checking if program exists in $PATH from ruby
body: <p>my scripts rely heavily on external programs and scripts.
  I need to be sure that a program I need to call exists.
  Manually, I'd check this using 'which' in the commandline.</p>
  <p>Is there an equivalent to <code>File.exists?</code> for things in <code>$PATH</code>?</p>
  <p>(yes I guess I could parse <code>%x[which scriptINeedToRun]</code> but that's not super elegant.</p>
  <p>Thanks!
  yannick</p>
  <hr />
  <p>UPDATE: Here's the solution I retained:</p>
  <pre><code> def command?(command)
         system(&quot;which #{ command} &gt; /dev/null 2&gt;&amp;1&quot;)
   end
  </code></pre>
  <hr />
  <h3>UPDATE 2: A few new answers have come in - at least some of these offer better solutions.</h3>
  <h3>Update 3: The <a href="https://github.com/djberg96/ptools" rel="noreferrer">ptools gem</a> has adds a &quot;which&quot; method to the File class.</h3>