Class: File

Inherits:
Object show all
Defined in:
lib/core_ext/file.rb

Overview

Extend the File class to add a function to check for a file in the load path.

Class Method Summary collapse

Class Method Details

.find_file_in_path(filename) ⇒ Object

find a file in the load path or raise an exception if the file can not be found.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
# File 'lib/core_ext/file.rb', line 7

def File.find_file_in_path(filename)
  $:.each do |path|
    file_with_path = path+'/'+filename
    return file_with_path if file?(file_with_path) 
  end

  raise ArgumentError, "Can't find file #{filename} in Ruby library path"
end