-
-
Save alexch/112505 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# likewise require | |
# by Pat Nakajima | |
# because I've been drinking more than Jack Barnette | |
# and | |
# to annoy John Susser and Aaron Peterson | |
# | |
# use to require files relative to the current file: | |
# | |
# likewise do | |
# require "foo" # require current-dir/lib | |
# require "lib/foo" # require current-dir/lib/foo | |
# end | |
module Kernel | |
def likewise(&blk) | |
Class.new { | |
def initialize(&block) | |
Object.instance_method(:instance_eval).bind(self).call(&block) | |
end | |
def require(path) | |
super(File.join(File.dirname(caller.first.split(':').first), path)) | |
end | |
}.new(&blk) | |
end | |
end | |
likewise do | |
require 'lib/fizz' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment