From: Kedar Mhaswade Date: 2013-03-15T00:07:34+09:00 Subject: Re: Understanding Ruby Classes, Objects and Methods. Robert Klemme wrote in post #1101612: > On Thu, Mar 14, 2013 at 3:14 PM, Kedar Mhaswade > wrote: >> Robert Klemme wrote in post #1101602: >>> On Thu, Mar 14, 2013 at 2:42 PM, Kedar Mhaswade >>> wrote: > >> module Mod, Anonclass is not returned when you do Someclass.superclass. >> ------------------------------------------------------------------- >> >> But if methods were only to be defined on class objects, I am not sure >> where the included module methods would come from without disturbing >> inheritance chain of classes. > > You could model it like this: every class has a list of included > modules which is initially empty. Every time a module is included > which is not included in this class or any super class it is prepended > to the list. Method lookup starts with the class itself, then > proceeds through the list of modules of this class and then proceeds > in the same way in the superclass; the process is stopped when the > first matching method is found. If not matching method is found the > lookup process starts again with name "method_missing". (That process > with end in class BasicObject which has a definition of > #method_missing.) But ... I thought a decision had already been made -- any method definition is to occur only on a class object. If that assumption is not true and method definitions can occur on modules, then yes, other implementation choices exist. > >> Any MRI experts -- how does it _really_ happen? >> And how about JRuby/Rubinius? > > You can look it up in the implementation - it's OSS. Thanks! I guess I will need to do that. > > Kind regards > > robert -- Posted via http://www.ruby-forum.com/.