From: Simon Strandgaard Date: 2004-02-20T21:19:58+09:00 Subject: Re: proposal: let kind_of take more arguments On Thu, 19 Feb 2004 18:21:47 +0100, Robert Klemme wrote: > "Simon Strandgaard" schrieb im Newsbeitrag >> On Thu, 19 Feb 2004 16:14:13 +0100, Robert Klemme wrote: >> > "Simon Strandgaard" schrieb im Newsbeitrag >> >> On Thu, 19 Feb 2004 15:43:05 +0100, Robert Klemme wrote: >> >> > >> >> > Why don't you just do >> >> > >> >> > def push(choice) >> >> > case choice >> >> > when Zero, One >> >> > @choices << choice >> >> > else >> >> > raise ArgumentError, "got #{choice.class}" >> >> > end >> >> > end >> >> >> >> a switch statement.. easier to read. >> >> However I like to do bailout as soon as possible, >> >> raising ArgumentError this late may make confusion. >> > >> > What do you mean by "late"? Do you mean that the line with "raise" >> > stands below the actual operation. Didn't think of that, but yes, >> > it might be confusing. OTOH, if you can read "case" then it's not >> > so difficult, is it? >> >> It isn't clear at first sight when the method bailouts, and if >> the switch statement spans over many lines, then its not visible at all >> that its capable of raising exceptions. >> >> Kind_of? similar to bouncer pattern, see >> http://www.rubygarden.org/ruby?BouncerPattern > > I see, you want to save the extra method check_arg_xyz(). :-) > Yes, it depends on if its understandable at first sight and isn't too visually disturbing. The concept of minimizing visual noise. If it isn't clear what is going on, then turn that piece of code into a check_something method. If the 'if-statement' is simple, then I typically don't make a check_something method out of that. -- Simon Strandgaard