1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/require_relative.rb
akr 125c0a0d93 * lib/require_relative.rb: check require_relative call in eval.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-02-16 02:46:27 +00:00

11 lines
320 B
Ruby

def require_relative(relative_feature)
c = caller.first
e = c.rindex(/:\d+:in /)
file = $`
if /\A\((.*)\)/ =~ file # eval, etc.
raise LoadError, "require_relative is called in #{$1}"
end
absolute_feature = File.expand_path(File.join(File.dirname(file), relative_feature))
require absolute_feature
end