From: Robert Dober Date: 2007-07-20T07:01:43+09:00 Subject: Re: RCR? Added syntax for chains that possibly return nil On 7/19/07, Stefan Rusterholz wrote: > 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/. > I hate it, this really should be syntax and furthermore it would make code ugly ( I know beauty lies in the eyes of the beholder ;). The original idea is quite good, why your shift? This is a terrible name pollution amongst other bad things :( Robert > -- I always knew that one day Smalltalk would replace Java. I just didn't know it would be called Ruby -- Kent Beck