From: Stefan Rusterholz Date: 2007-07-20T01:53:19+09:00 Subject: Re: RCR? Added syntax for chains that possibly return nil Eugen Minciu wrote: > > class Object > alias regular_method_missing method_missing > def method_missing(meth) > if meth.to_s[0]=='_'[0] > return nil > else > regular_method_missing(meth) > end > end > end Reworked it a bit: class Object alias method_missing_no_underscore method_missing def method_missing(m,*a,&b) m.to_s[0] == ?_ ? send(m.to_s[1..-1],*a,&b) : method_missing_no_underscore(m,*a,&b) end end class NilClass alias method_missing_no_underscore method_missing def method_missing(m,*a,&b) m.to_s[0] == ?_ ? nil : method_missing_no_underscore(m,*a,&b) end end while line = gets._chomp ... end so ._ simulates -> with that hack. Thanks for the idea. Should check for m.to_s != "_", though, since that method is used e.g. with gettext. Regards Stefan -- Posted via http://www.ruby-forum.com/.