Skip to content

Instantly share code, notes, and snippets.

@alexch
Forked from nakajima/likewise.rb
Created May 16, 2009 00:03
Show Gist options
  • Save alexch/112505 to your computer and use it in GitHub Desktop.
Save alexch/112505 to your computer and use it in GitHub Desktop.
# 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