[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Did this stop working? Or did it ever work? (metamagic

Daniel Waite

5/1/2008 10:43:00 PM

I wrote a tutorial a few months ago that describes how/why the following
worked:

module Translator

module ClassMethods

def translate
end

end

def included(receiver)
receiver.extend(ClassMethods)
end

end

class C

include Translator

end

But, now it doesn't work.

Effectively I expect the translate method to become a class-level method
of C. Instead I'm told C doesn't know about that method.

If I call C.extend(Translator::ClassMethods) I get what I'd expect.

Have I been wrong this entire time or did something change?

ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-darwin9.2.2]
--
Posted via http://www.ruby-....

2 Answers

Mikael Høilund

5/1/2008 10:57:00 PM

0

On May 2, 2008, at 0:43, Daniel Waite wrote:
> module Translator
>
> module ClassMethods
>
> def translate
> end
>
> end
>
> def included(receiver)

You forgot the self. here. ``included'' is a module method.
def self.included(receiver)
Then it works.



Daniel Waite

5/1/2008 11:08:00 PM

0

Mikael Høilund wrote:
> On May 2, 2008, at 0:43, Daniel Waite wrote:
>> module Translator
>>
>> module ClassMethods
>>
>> def translate
>> end
>>
>> end
>>
>> def included(receiver)
>
> You forgot the self. here. ``included'' is a module method.
> def self.included(receiver)
> Then it works.

*face palm*

Thanks, Mikael. Glad I wasn't _too_ far off. :)
--
Posted via http://www.ruby-....