From: Robert Klemme Date: 2013-03-15T01:38:18+09:00 Subject: Re: Understanding Ruby Classes, Objects and Methods. On Thu, Mar 14, 2013 at 4:07 PM, Kedar Mhaswade wrote: > 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. They *do* - from perspective of a language user. I would try to cleanly separate the language from implementation details. That will make understanding for newcomers much easier. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/