From: dblack@... Date: 2007-07-02T07:17:27+09:00 Subject: Re: Variable argument number and behaviour Hi -- On Mon, 2 Jul 2007, Ryan Allan wrote: > Thank you Stefano. > You're right; the empty? method is nicely obvious. > I do have a further question, however. You've highlighted a problem > with my original idea, but I don't understand it. > >> Besides, even if it >> had been possible, your approach would have had a problem: you wouldn't have >> been able to distinguish the case of a single nil argument from the case of >> no arguments: >> >> function(nil) >> >> function() >> >> The correct approach solves this problem: if no arguments are passed, >> sometimes is empty (empty? returns true); otherwise it's not empty, even >> if all arguments are nil. > > What is the difference between no arguments and a single nil argument? > It seems to me that the cases are logically equivalent. Ruby treats them > separately? Yes, because nil is an object. def meth(x) p x end meth(1) # 1 meth(nil) # nil meth # ArgumentError: wrong number of arguments David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)