Trans
8/17/2006 6:24:00 PM
Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: using a module at the toplevel doesn't work"
> on Fri, 18 Aug 2006 02:40:05 +0900, "Trans" <transfire@gmail.com> writes:
>
> |Yukihiro Matsumoto wrote:
> |
> |> I don't think I understand you. Can you elaborate?
> |
> |Sure thing. It seems natural to me that "main" would a module of the
> |form:
> |
> | module Main
> | extend self
> | end
> |
> |Such a module provides all the characteristics of the toplevel --def,
> |include, etc.
>
> Why? If it is really required it's fairly easy to add toplevel
> methods like we did for #include.
See what I wrote to Pit Capitain. Even if I define the missing toplevel
methods:
def define_method( meth, &block )
Object.class_eval do
define_method( meth, &block )
private meth
end
end
def ancestors
Object.ancestors
end
include MyModule
I still get errors because state (e.g. instance vars used in MyModule)
are being stored in the toplevel instance of Object, main, and not in
Object. I got methods going one way and instance vars going another.
Is there a reason the toplevel _can't_ be Kernel instead of a specal
instance of Object? Just seems like that would be hek of a lot easier
all around.
Thanks,
T.