Module: Readapt::Finder
- Included in:
- Debugger
- Defined in:
- lib/readapt/finder.rb
Overview
Methods to find a program in the current directory or one of the environment paths.
Class Method Summary collapse
-
.find(program) ⇒ String
Get the program’s fully qualified path.
-
.which(program) ⇒ String
Search the environment paths for the given program.
Class Method Details
.find(program) ⇒ String
Get the program’s fully qualified path. Search first in the current directory, then the environment paths.
17 18 19 20 |
# File 'lib/readapt/finder.rb', line 17 def find program return program if File.exist?(program) which(program) || raise(LoadError, "#{program} is not a valid Ruby file or program") end |
.which(program) ⇒ String
Search the environment paths for the given program.
26 27 28 29 30 31 32 |
# File 'lib/readapt/finder.rb', line 26 def which program ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exe = File.join(path, program) return exe if File.file?(exe) end nil end |