From: Francis Hwang Date: 2005-05-29T12:05:53+09:00 Subject: Re: preventing Object#send from dispatching to a global method? Okay, thanks for the tip, that's definitely giving me some ideas. Builder::BlankSlate's strategy seems like something for me to follow. Here's an added piece of complexity: this logic has to depend on values set during the class definition. I'm talking, BTW, about Lafcadio's DomainObjects. So: def fname; "here's an unfortunate coincidence"; end class User < Lafcadio::DomainObject text 'fname' text 'lname' end I wanted to trigger some methods to undefine instance methods of 'fname' in User, but I can't do that with Class.inherited -- because at the time that the User class is being defined, I don't know that I'm looking for global methods named 'fname' and 'lname'. It feels like, from perusing the archives, there is currently no way to be notified when a class definition is finished. Correct? On May 28, 2005, at 10:29 PM, Jim Weirich wrote: > > On May 28, 2005, at 11:42 AM, Francis Hwang wrote: > >> Is there a way to prevent Object#send from dispatching to a global >> method? By which I mean: >> > > You could look at how Builder::BlankSlate handles it. It uses method > defined hooks to undefine any methods added to any ancestors. You can > find BlankSlate in the builder gem. > > For example > > traken$ irb --simple-prompt > >> require 'builder/blankslate' > => false > >> class Empty < Builder::BlankSlate > >> def inspect > >> "" > >> end > >> def method_missing(sym, *args) > >> puts "Calling #{sym}(#{args.join(',')})" > >> end > >> end > => nil > >> e = Empty.new > => > >> e.hi > Calling hi() > => nil > >> def hi() "HI" end > => nil > >> e.hi > Calling hi() > => nil > > Francis Hwang http://fhwang.net/