From: Robert Klemme Date: 2004-05-12T01:38:53+09:00 Subject: Re: Proposal: Object#send(nil) -> self "Gavin Sinclair" schrieb im Newsbeitrag news:1431045619661.20040512020216@soyabean.com.au... > A quick one. I see some sense in Object#send accepting 'nil' as the > message. You send no message, you get the plain object. Does anyone > agree? > > #send is clearly useful when you want to vary the message sent to an > object based on some condition. Sometimes the default condition is to > send no message, but that can't be coded as elegantly. > > For example: > > date_colour_msg = > case Date.today - date > when 0 then :red > when 1 then :yellow > when 2..5 then :green > else > nil # Default: whatever the normal colour is. > end > # how about date_str = date.to_s.send(date_colour_msg) if date_colour_msg OTOH you can do date_str = case Date.today - date when 0 then date.to_s.red when 1 then date.to_s.yellow when 2..5 then date.to_s.green else default_color # Default: whatever the normal colour is. end The more OO way would be to use a Hash: COLORS = { 0 => :red ... } COLORS.default= default_color date_str = COLORS[Date.today - date] > That example's not too contrived, is it? I found a bit irritating that you send :red, :yellow etc. to a String. Regards robert