From: "David A. Black" Date: 2008-10-04T23:16:27+09:00 Subject: Re: No warning for redefine Hi -- On Sat, 4 Oct 2008, Daniel DeLorme wrote: > David A. Black wrote: >> >> On Fri, 3 Oct 2008, Han Holl wrote: >>> >>> Shouldn't the following: > [snip] >>> produce something like: >>> >>> demo.rb:9: warning: method redefined; discarding old function >>> >>> Behaviour now is to discard the mixed-in method silently. >> >> It's not discarded; it's still there (in the module) and you can use >> it with other classes, or reach it through 'super' in the override. > > But since the override doesn't use super, in effect it has the same effect as > discarding the included 'function', at least as far as the main object is > concerned. I wish ruby would output a warning for cases like this, i.e. > "warning: method `foo' ignores method defined in /path/to/file.rb:123" Yikes. Be careful what you wish for :-) That would put a damper on a lot of code, as well as slowing things down (the 'super' determination could only be made at runtime) and spewing endless errors. For example: {}.select ... would give you a warning, because the Hash override of Enumerable#select does not call super. There's absolutely nothing fishy or wrong with not calling super, so there's nothing to warn about. The whole object/class model of Ruby is based on the idea of a method search-path, to which you can prepend classes and modules precisely to prevent the execution of earlier definitions of methods. Any issues with name clashing and such (of which there shouldn't be many, if any, since you'd presumably be familiar with the class you're inheriting from) would be exposed by tests. David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL Advancing with Rails January 19-22 Fort Lauderdale, FL * * Co-taught with Patrick Ewing! See http://www.rubypal.com for details and updates!