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

D

Daniel Waite

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]
 
M

Mikael Høilund

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.
 
D

Daniel Waite

Mikael said:
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. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top