From: Trans Date: 2006-10-03T22:29:03+09:00 Subject: Re: Why can't I get on Top? MonkeeSage wrote: > Hi Trans, > > How about a workaround for now? Something like: > > class << self > def include(mod) > self.extend(mod) > if in_toplevel? > p 'Do NOT use me from toplevel' > end > end > end > > module NoTopLevel > def in_toplevel? > self.to_s == 'main' > end > end > > include NoTopLevel Well, let me show you what I'm actually doing: module Taskable def self.included( base ) if base.toplevel? require 'main_as_module.rb' end end end main_as_module.rb is actually a bit of code that will add every module method there is to toplevel (ie. main). So you see I'm actually trying to selectively mitigate the issue were talking about. I could just require this lib no matter what and be done with it, but I thought it would be better if I only included it if it is needed --no sense in loading code that's not used. But it looks like I don't have much choice. However, I did manage this work-around: module Taskable def self.included( base ) if base == Object require 'main_as_module.rb' end end end That catches it, although it also catches when Taskable is included in Object too. But that's only one exception that won't cause any harm, so it's an accecptable work around. T.