From: Morton Goldberg Date: 2006-08-08T06:34:04+09:00 Subject: Re: How to react on nil or wrong object-type as parameter IMHO handle_client_well is simply bad code that needs to be fixed. It needs to be rewritten into something like: def handle_client_well client if client.check_portfolio then client.decrease_acoount(200) @invitations_to_golf.push client end end Further, check_portfolio must be rewritten to return true if the clients portfolio entitles him to be "well handled". When the code is fixed, the kinds of problems you anticipate don't occur. Regards, Morton On Aug 7, 2006, at 4:37 PM, Yochen Gutmann wrote: > So if I do understand you all correctly, in Ruby you put the > responsible > to the caller of a method (eg print_salary()). If you want to test > that > method, you test it only with the proper types. The next thing > would be > testing the method which includes the call of print_salary() if it > calls > this methods with the wrong types of parameter. Is this right? > > One problem in this concept is that if some operations might work on a > parameter-object and the following is not the exception is thrown when > the object is already modified. > > class Bank > @invitations_to_golf > > def handle_client_well client > client.decrease_acoount(200) > client.check_portfolio > @invitations_to_golf.push client > end > > end > > jon_doe = LowBudgetClient.new > big_boss = VeryRichClient.new > big_money = Bank.new > > big_money.handle_client_well big_boss > big_money.handle_client_well jon_doe // poor guy has no portfolio > > So, when the hcw-method is called with jon_doe, he has to pay for > better > handling but since he has no portfolio the exception is thrown > before he > is entering the golf course. > > One solution might be a exception around the method-body (yes, again > ;-)) and a include an ensure to increase the account again if > something > broke. But again, this procedure would fail if there are many modifing > operations. > > Perhaps I am still thinking too Java'ish and these are high > theorectical > problems or I still dont get it. > > Yochen > > -- > Posted via http://www.ruby-forum.com/. >