"Robert Klemme" <bob.news / gmx.net> 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.

>
> > 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::<constant>" to the mixin (reported from
the point where the class constant is defined). Using
....self.class.const_get("<constant>") works fine though in the mixin.

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.

// Johan