From: Jim Freeze Date: 2005-07-27T05:28:14+09:00 Subject: Re: What's so special about operators, built-in classes and modules? * Joel VanderWerf [2005-07-27 04:52:29 +0900]: > > Thanks Forian. For some reason I always thought that including a mod > > would shadow old methods. > > I suppose for my method to work (no pun intended), the standard > > operating procedure is to: > > > > class B > > alias :_orig_f > > remove_method :f > > include Mod > > end > > > Including a module is just like inheriting from a class--the module is > above you in the ancestor list. I guess the intuitive meaning of > "include" might be different--one might think it meant "define all > methods from the module at this point in my class definition". Maybe > "inherit " would be a better name for the construct... My simple thought process was always thinking that 'include'ing a Module was the same as writing the methods myself. So class A def m puts "A#m" end def m puts :m end end A.new.m #=> :m was the same thing as module Mod def m puts :m end end class A def m puts "A#m" end include Mod end A.new.m #=> :m So, I thought it was redefining the method and the old method was being lost if it did not have an alias. But, as you say, it is more like inheritance. > So would the RCR be for a construct that inserted a module between each > instance of B and B itself? Would be nice if the notation was external to the class since there is no difference between: class A include Mod def m; puts "A#m"; end end and class A def m; puts "A#m"; end include Mod end -- Jim Freeze