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

Discussion in 'Ruby' started by Daniel Waite, May 1, 2008.

  1. Daniel Waite

    Daniel Waite Guest

    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-forum.com/.
    Daniel Waite, May 1, 2008
    #1
    1. Advertising

  2. 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.
    Mikael Høilund, May 1, 2008
    #2
    1. Advertising

  3. Daniel Waite

    Daniel Waite Guest

    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-forum.com/.
    Daniel Waite, May 2, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. phoenix

    Why did my events stop working?

    phoenix, Nov 12, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    379
  2. John Salerno

    Why did my stylesheet stop working?

    John Salerno, Nov 20, 2007, in forum: HTML
    Replies:
    15
    Views:
    676
    John Salerno
    Nov 21, 2007
  3. Angus
    Replies:
    5
    Views:
    438
    Ben Bacarisse
    Jul 18, 2010
  4. Jason
    Replies:
    0
    Views:
    171
    Jason
    Jul 6, 2004
  5. Dude
    Replies:
    1
    Views:
    74
    John Joyce
    Mar 28, 2007
Loading...

Share This Page