class Object
Public Instance Methods
autoload_relative(symbol, relative_path)
click to toggle source
# File lib/hippo_eyeDoc/utilities.rb, line 33 def autoload_relative(symbol, relative_path) file = caller.first.split(/:\d/,2).first autoload symbol, File.expand_path(relative_path, File.dirname(file)) end
require_relative(relative_feature)
click to toggle source
Yep, you're looking at it! This gem is pretty small, and for good reason. There's not much to do! We use split to find the filename that we're looking to require, raise a LoadError if it's called in a context (like eval) that it shouldn't be, and then require it via regular old require.
Now, in 1.9, “.” is totally removed from the $LOAD_PATH. We don't do that here, because that would break a lot of other code! You're still vulnerable to the security hole that caused this change to happen in the first place. You will be able to use this gem to transition the code you write over to the 1.9 syntax, though.
# File lib/hippo_eyeDoc/utilities.rb, line 23 def require_relative(relative_feature) file = caller.first.split(/:\d/,2).first raise LoadError, "require_relative is called in #{$1}" if /\A\((.*)\)/ =~ file require File.expand_path(relative_feature, File.dirname(file)) end