From: Robert Klemme Date: 2011-08-22T04:46:18+09:00 Subject: Re: Gritty Details of super() On Sun, Aug 21, 2011 at 7:48 PM, Gavin Kistner wrote: > On Aug 21, 2011, at 11:21 AM, luke gruber wrote: > >> But the issue I ran into was calling super in a singleton method of a >> class object ie: Someclass.somemethod(), and hoping that my included >> module that also defined a singleton method would catch the call to >> super(). > > This isn't related to super so much as it is the nature of inheritance and modules in Ruby. See this diagram: > > http://phrogz.net/RubyLibs/RubyMethodLookupFlow.png > > If you want inheritance for singleton methods of an object from a module you must _extend_ the object with a module defining _instance_ methods. > > For example: > > module Foo >  def self.included(klass) >    klass.extend(ClassMethods) >  end >  module ClassMethods >    def bar; …; end >  end > end > > class Bar >  include Foo > end > > Bar.bar > > (typed on the phone; forgive untested errors) Direct extending works as well 1 #!/usr/bin/env ruby 2 3 module Mod 4 5 def who 6 "mod" 7 end 8 9 end 10 11 class Test 12 extend Mod 13 14 def self.who 15 ret = super 16 [ret, "test"] 17 end 18 19 end 20 21 p Test.ancestors # includes Mod 22 p Test.superclass # is Object!! 23 p Test.who # DOESN'T WORK Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/