Skip to content

Instantly share code, notes, and snippets.

@trshafer
Created November 10, 2012 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trshafer/4049387 to your computer and use it in GitHub Desktop.
Save trshafer/4049387 to your computer and use it in GitHub Desktop.
Load Blank Modules when const missing
# 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