Created
April 26, 2012 16:01
-
-
Save boggle/2500585 to your computer and use it in GitHub Desktop.
Nice way to add reloading support to a ruby gem's top-level module
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
module Foo | |
def self.files | |
f = [] | |
f << 'foo/a' | |
f << 'foo/b' | |
f | |
end | |
def self.load_relative(f) | |
path = "#{File.join(File.dirname(caller[0]), f)}.rb" | |
load path | |
end | |
def self.reload! | |
files.each { |f| load_relative f } | |
end | |
end | |
# normal loading during require | |
Foo.files.each { |f| require_relative f } | |
# reloading in irb | |
Foo.reload! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment