Kent Sibilev
12/14/2004 4:30:00 PM
Oh, I didn't notice 'extend' in the code. Sorry about the noise.
Cheers,
Kent.
On Dec 14, 2004, at 10:37 AM, Robert Klemme wrote:
>
> "Kent Sibilev" <ksibilev@bellsouth.net> schrieb im Newsbeitrag
> news:07703F80-4DE5-11D9-B79B-000A95C700E8@bellsouth.net...
>> By including a mixin module into a class you can add only instance
>> methods unless you implement Module#append_features(or
>> Module#included), if that's what you want to know.
>
> No. Note the fine difference between include and extend (see code
> below).
> But anyway thanks for calling.
>
> Also, with a little magic you can add class and instance methods either
> way (i.e. with include and extend).
>
> Kind regards
>
> robert
>
>
Cheers,
Kent.
>>
>> On Dec 14, 2004, at 7:52 AM, Johan Nilsson wrote:
>>
>>>
>>> "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"-synd
>>> rome).
>>>
>>> In english, I want to create an instance of Foo from within the
> mixin's
>>> supplied class method. The first question still applies though.
>>>
>>> // Johan
>>>
>>>
>>
>>
>>
>
>