From: Todd Corenson Date: 2007-11-07T09:49:28+09:00 Subject: Re: Superclass of a module Actually, Module does provide append_features. It's just that append_features is a private instance method: Module.private_instance_methods.include?("append_features") # => true I now see what is going on in general. Class Class or Class Module instance methods become Class or Module methods in instances of Class or Module. Instances of Class or Module create singletons to reference their Class or Module methods. When an instance method of the same name exists in Class or Module, that method is invoked by a call to super in the Class or Module method defined in the singleton. No superclass is necessarily involved. Rick Denatale wrote: > On 11/5/07, Todd Corenson wrote: >> would make append_features a module method and yet >> Module.new.respond_to?(:append_features, true) is true. For a class, >> this implies that append_features would be an instance method. I take >> it this works differently for modules? > > No, Foo is an instance of Module. > > module Foo > def self.append_features(b) > super > end > end > > The self.append_features in the def means that we are defining the > method in the context > of the singleton class of Foo. Try running this: > class Module > def provides_method(meth) > instance_methods.include?(meth.to_s) ? "provides #{meth}" : "does > not provide #{meth}" > end > end > > module Foo > def self.append_features(b) > puts "I am #{self}" > puts "My class is #{self.class} which > #{self.class.provides_method(:append_features)}" > sing_class = class < puts "My singleton class is #{sing_class} which > #{sing_class.provides_method(:append_features)}" > super > end > end > > class C > include Foo > end > > which produces the following output: > > I am Foo > My class is Module which does not provide append_features > My singleton class is # which provides append_features > > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ -- Posted via http://www.ruby-forum.com/.