From: Intransition Date: 2009-12-30T04:49:44+09:00 Subject: Re: Using #include at the instance level? On Dec 29, 11:55 am, Robert Klemme wrote: > Then your block needs to contain a class definition.  You can use the > block only for _one_ thing - either class / module def or code you > want to execute.  Granted, you can have code executed in a class > definition as well but the definition becomes only usable *after* the > definition has been executed in its entirety. That's true. But the execution of the block is only for the definition of things which get run later. > Maybe you haven't > decided yet what you want the block for and that is causing your > headaches. The block is for defining unit tests. Eg. testcase SomeClass do testunit :somemethod => "some concern" do ... end end > > Haven't tested it yet, but that should allow #include to work no > > problem. Unfortunately it means defining all my dsl methods at the > > class level --not even sure the instance level would be of any use in > > this case either, in which case the ._new can be dropped -- kind of > > stupid, just to get #include to work. But what else can I do? > > > I almost feel like I'm having a mental block and there is actually an > > easy way to do this. > > What stops you from doing the include outside? > > include Your::Module::Of::Choice > > TestCase.new Foo do >   x = ChoiceClass.new >   x.method_invocation(123) > end Yes, I am able to do that. But I want to avoid polluting the top level. You know what really gets me is that even though I get an "uninitialized constant" error, there is no place I seem to be able to define a #const_missing method to catch it.