"Johan Nilsson" <johan.nilsson / ---.esrange.ssc.se> schrieb im Newsbeitrag news:1103028594.879ec90c8d4eeda7699d84d52c2d5a65 / teranews... > > "Robert Klemme" <bob.news / gmx.net> wrote in message > news:327uc2F3j9j3eU1 / individual.net... > > > > "Johan Nilsson" <johan.nilsson / ---.esrange.ssc.se> schrieb im Newsbeitrag > > news:1103018684.0021a1444d2417eb0d9c6eddf9e60f0d / teranews... > > > Hi, > > > > > > some newbie questions: > > > > > > - How can/should I access a class constant from a mixin? The only thing > > I've > > > managed to get working is "const_get("name of const")". > > > - Is it possible to access protected methods from mixins? I'm trying to > > > create a mixin alike the following: > > > > > > --- > > > module StaticCreateMixin > > > def create_from(stuff) > > > obj = self.new > > > obj.my_stuff.<modifiying fn>!(stuff) > > > obj > > > end > > > end > > > > > > class Foo > > > extend StaticCreateMixin > > > > > > def my_stuff > > > @stuff > > > end > > > > > > protected :my_stuff > > > end > > > > > > f = Foo.static_create("some stuff") > > > > Your example misses something, does it? It's not completely clear to me > > what you want to do. Or did you misspell create_from as static_create? > > Oops. Yes, I'm a very bad speller (or it could be the > "extract-a-minimal-sample-from-actual-code-but-don't-bother-to-test-it"-sy nd > rome). 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. > 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 irb(main):034:0* Test.test_it "bar" => nil Kind regards robert