From: Tim McIntyre Date: 2006-09-03T03:04:05+09:00 Subject: Re: catch all method... e.g perl's autoload --Apple-Mail-2-671837327 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Yep, thats what I was looking for. Thanks Eric! still have some ActiveRecord idiosyncrasies holding up what I want to do here but thats the gist. Thanks again! Tim On Sep 2, 2006, at 10:15 AM, Eric Hodel wrote: > On Sep 2, 2006, at 10:02 AM, Tim McIntyre wrote: >> Does ruby have a catchall method similar to perl's autoload? > > Does this sound right? > > $ ri Kernel#method_missing > -------------------------------------------------- > Kernel#method_missing > obj.method_missing(symbol [, *args] ) => result > ---------------------------------------------------------------------- > -- > Invoked by Ruby when obj is sent a message it cannot handle. > symbol is the symbol for the method called, and args are any > arguments that were passed to it. By default, the interpreter > raises an error when this method is called. However, it is > possible to override the method to provide more dynamic behavior. > The example below creates a class Roman, which responds to > methods > with names consisting of roman numerals, returning the > corresponding integer values. > > class Roman > def romanToInt(str) > # ... > end > def method_missing(methId) > str = methId.id2name > romanToInt(str) > end > end > > r = Roman.new > r.iv #=> 4 > r.xxiii #=> 23 > r.mm #=> 2000 > > > -- > Eric Hodel - drbrain@segment7.net - http://blog.segment7.net > This implementation is HODEL-HASH-9600 compliant > > http://trackmap.robotcoop.com > > > > Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind. - Dr. Seuss --Apple-Mail-2-671837327--