Skip to content

Commit

Permalink
Fixed require_relative. Fixes #2976. Fixes #3163.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Dec 3, 2014
1 parent 8827765 commit 6dfb925
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions kernel/common/code_loader.rb
Expand Up @@ -137,10 +137,14 @@ def require
# check to make sure it's not called inside of an eval.
def self.require_relative(name, scope)
script = scope.current_script
if script && script.data_path.nil?
raise LoadError.new "cannot infer basepath from #{script.file_path}"
elsif script
require File.expand_path(name, File.dirname(File.realdirpath(script.data_path)))
if script
if script.data_path
path = File.dirname(File.realdirpath(script.data_path))
else
path = Dir.pwd
end

require File.expand_path(name, path)
else
raise LoadError.new "Something is wrong in trying to get relative path"
end
Expand Down

0 comments on commit 6dfb925

Please sign in to comment.