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

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]

On May 2, 2008, at 0:43, Daniel W. 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.

Mikael Høilund wrote:

On May 2, 2008, at 0:43, Daniel W. 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. :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs