Created
November 10, 2012 01:20
-
-
Save trshafer/4049387 to your computer and use it in GitHub Desktop.
Load Blank Modules when const missing
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
# pretty much copied from active_support | |
module ModuleConstMissing | |
def self.append_features(base) | |
base.class_eval do | |
# Emulate #exclude via an ivar | |
return if defined?(@_const_missing) && @_const_missing | |
@_const_missing = instance_method(:const_missing) | |
remove_method(:const_missing) | |
end | |
super | |
end | |
def const_missing(const_name, nesting = nil) | |
mod = Module.new | |
const_set const_name, mod | |
mod | |
end | |
end | |
Module.class_eval { include ModuleConstMissing } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment