Pit Capitain
10/28/2008 7:05:00 AM
2008/10/27 Xavier Shay <contact@rhnh.net>:
> I'm autoloading a file, it contains this part, so it's basically the
> public interface.
>
>> class self::A
>> parent.foo
>
> And for that reason this is a much nicer, I think. But if it can't be
> done like this, it can't be done...
Xavier, I don't know why you want to have an anonymous module with a
local constant, but if you really need this and are willing to change
the public interface a little bit you could do
m = Module.new
m.module_eval do
# methods for dependent classes
def depend(file)
puts "#{self} depends on #{file}"
end
# methods to define a dependent class
def self.const_missing(name)
const_set(name, Class.new)
end
def self.dependent_class(cls, &blk)
parent_module = self
cls.class_eval do extend(parent_module) end
cls.class_eval(&blk)
end
# public interface for dependent classes
dependent_class self::A do
depend("afile.rb")
end
end
Regards,
Pit