Method: Kernel#fastruby_require

Defined in:
lib/fastruby/custom_require.rb

#fastruby_require(path) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fastruby/custom_require.rb', line 25

def fastruby_require(path)
  if path =~ /\.so$/
    require(path)
  else
    FastRuby.logger.info "trying to load '#{path}'"

    complete_path = path + (path =~ /\.rb$/ ? "" : ".rb")

    $LOAD_PATH.each do |load_path|
      begin
        source = nil
        File.open(load_path + "/" + complete_path) do |file|
          source = file.read
        end

        FastRuby.logger.info "loading '#{load_path + "/" + complete_path}'"

        fastruby source
        return true
      rescue Errno::ENOENT
      end
    end

    raise LoadError
  end
end