From: Mark Hubbart Date: 2004-05-12T05:41:40+09:00 Subject: Re: Proposal: Object#send(nil) -> self On May 11, 2004, at 9:04 AM, Gavin Sinclair wrote: > 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 > > date_str = date.to_s.send(date_colour_msg) > > That example's not too contrived, is it? While the example seems *somewhat* contrived :) , I can see situations where it would be handy... And since #sending nil currently raises an error, I doubt it would break anyone's code. I would consider it a good rcr, myself. class Object alias no_nil_send send def send(*args) args.first ? no_nil_send(*args) : self end end Something like this, I assume? cheers, --Mark