Top Level Namespace

Defined Under Namespace

Modules: Hippo

Instance Method Summary collapse

Instance Method Details

#autoload_relative(symbol, relative_path) ⇒ Object



33
34
35
36
37
# File 'lib/hippo/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) ⇒ Object

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.

Raises:

  • (LoadError)


23
24
25
26
27
28
29
30
# File 'lib/hippo/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