From: Brian Mitchell Date: 2005-12-29T10:28:08+09:00 Subject: Re: get mixin's name On 12/28/05, Payton Swick wrote: > A somewhat weird situation. > > I have a module which I include in a class using Module#extend. That > module defines an instance method which returns the name of the module > that defined the method. Currently, I do that by hard-coding the string > into the method definition, but it seems that there should really be a > better way. The string is simple though... but if you want another way you could look at Module#ancestors on the singleton class (since you use extend). module A end a = "some_object".extend A #=> "abc" singleton_class = class << a; self end # #> singleton_class.ancestors #=> [A, String, Enumerable, Comparable, Object, Kernel] singleton_class.ancestors.first #=> A # If you want it in string form: singleton_class.ancestors.first.to_s #=> "A" You would want to wrap this up in some sort of method (at least the class << part). Brian.