From c2f58becffdc8221f0e0448c80ce72f169797803 Mon Sep 17 00:00:00 2001 From: Jacek Jakubik Date: Sun, 15 Sep 2013 20:43:42 +0200 Subject: [PATCH] easier module generator --- core/efuns.rb | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/core/efuns.rb b/core/efuns.rb index 02b55dc..b4c44a5 100644 --- a/core/efuns.rb +++ b/core/efuns.rb @@ -104,38 +104,16 @@ def game_path(klass) class Module def const_missing(name) - log_warning("const missing: #{self.to_s + "::" + name.to_s} - trying to load/generate...") modules = self.to_s.split("::") if modules.first == "World" - modules << name.to_s - - filename = Rmud.root + "/" + modules.map(&:downcase).join("/") - - if File.exists?(filename) && File.directory?(filename) - generate_empty_module(filename) - end - - if const_get(name) - return modules.join("::").constantinize - end + log_warning("Const missing: #{self.to_s}::#{name} - adding new constant") + const_set(name, Module.new) else - raise "uninitialized constant #{name}" + raise NameError, "uninitialized constant #{name}" end end end -def generate_empty_module(filename) - d = filename.gsub(Rmud.root + "/", "") - modules = d.split("/") - - evaled = "" - modules.each {|m| evaled << "module #{m.capitalize} "} - modules.each {|m| evaled << "end; "} - - eval(evaled) - log_notice("[code] - module #{modules.map(&:capitalize).join("::")} generated") -end - def load_file(filename) log_notice("[core] - load file - loading file #{filename}") require filename