Skip to content

Commit

Permalink
easier module generator
Browse files Browse the repository at this point in the history
  • Loading branch information
rindek committed Sep 15, 2013
1 parent 5bbec0c commit c2f58be
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions core/efuns.rb
Expand Up @@ -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
Expand Down

0 comments on commit c2f58be

Please sign in to comment.