From: Alexey Petrushin Date: 2008-10-11T20:19:18+09:00 Subject: Re: Automatic ClassLoader (to eliminate 'require') Thanks! It works! :) Implementation: GLOBAL_BINDING = binding class Module def const_missing(const) full_class_name = (self == Object or self == Module) ? const.to_s : "#{self.name}::#{const}" file = full_class_name.gsub('::', '/') if File.directory?(file) eval "module #{full_class_name} end", GLOBAL_BINDING elsif File.exist?(file+".rb") script = File.read(file+".rb") unless self == Object or self == Module script = "\ module #{self.name} #{script} end " end eval script, GLOBAL_BINDING else raise "Class not found: #{full_class_name}" end result = eval "#{full_class_name}", GLOBAL_BINDING return result if result raise "Class not found: #{full_class_name}" end end # A/B/C.rb # # class C # end # A::B::C.new Notes: - in the script for the class C, we write just C, instead of all A::B::C - there are no really A and B modules, they are generated on the fly. -- Posted via http://www.ruby-forum.com/.