From: Robert Klemme Date: 2004-12-15T00:12:19+09:00 Subject: Re: Mixin questions "Johan Nilsson" schrieb im Newsbeitrag news:1103032112.3aa9129fd718fc17e4d9eb2e027a3e52@teranews... > > "Robert Klemme" wrote in message > news:3286taF3it29pU1@individual.net... > > > > [snip] > > > > > You don't necessarily need a class method. You can make it a method in > > Kernel, too: > > > > module Kernel > > private > > def static_create(cl, stuff) > > o = cl.new > > o.my_stuff.duh! stuff > > o > > end > > end > > > > f = static_create( Foo, "some stuff") > > > > Somehow I feel that a mixin might be a bit over the top - unless of course > > the mixin contains more code. > > Might be. Still I'd prefer: > > f = Foo.static_create("some stuff") > > I still don't see how the mixin can get to the protected methods though - I > get "NoMethodError: protected method 'my_stuff' called for ..." if I try > somehing like my original code. I haven't a solution for this yet. I tried with instance_eval but to no avail. Maybe send works. Did you try that? > > > In english, I want to create an instance of Foo from within the mixin's > > > supplied class method. The first question still applies though. > > > > You mean like this? > > > > module Mix > > def test_it > > p self::FOO > > end > > end > > > > class Test > > extend Mix > > FOO = "bar" > > end > > Yes, but in my (unfortunately) more complex case I get "dynamic constant > assignment" whenever I add "self::" to the mixin (reported from > the point where the class constant is defined). But then you're assigning the constant more than once. From your example I though you just wanted to access (= read) it. Which Ruby version are you using? > Using > ...self.class.const_get("") works fine though in the mixin. Strange. > The code is a bit too much to post though, if I can reduce it I'll try and > post the actual failing code instead. Yeah, it would be good to see the real source of the problem. At the moment I feel a bit tapping in the dark. :-) Kind regards + good luck robert