Hi -- On Mon, 14 Sep 2009, Gaspard Bucher wrote: > Hi List ! > > I found a tricky thing: if you use define_method and then include a > module that contains a method with the same name, the method in the > module is just ignored. > > Why is that so ? > > How can I overwrite a method defined through 'define_method' ? > > Example ruby code: http://bit.ly/2NjP5w It's a matter of the order of method lookup. In general, an object looks for a method first in its class, and then in modules mixed into that class. module M def x; puts "x in M"; end end class A def x; puts "x in A"; end include M end A.new.x # x in A It's the same if the method is defined with #define_method. Yehuda Katz has recently proposed that there be a way to insert a module in the lookup order before the class. I'm not sure where that proposal stands at the moment. David -- David A. Black, Director Ruby Power and Light, LLC (http://www.rubypal.com) Ruby/Rails training, consulting, mentoring, code review Book: The Well-Grounded Rubyist (http://www.manning.com/black2)