From: Luigi Ballabio Date: 2001-03-24T03:08:06+09:00 Subject: [ruby-talk:13148] Re: How would Ruby say this? At 01:50 AM 3/24/01 +0900, you wrote: >Lyle Johnson: > > > >... > > initial = 42.0 > > status, result = getValue(initial, "What it is?") > > if status > > puts "The user responds: #{result}" > > else > > puts "The user cancelled without responding" > > end > > > > begin > > initial = 42.0 > > result = getValue(initial, "What it is?") > > puts "The user responds: #{result}" > > rescue CancelError > > puts "The user cancelled without responding" > > end > > ... > >Dave Thomas: > > ... > > A third option would be to return 'nil' on no input (as presumably nil > > can never be returned). Then you can write > > > > if res = getValue("What's the frequency..") > > process ... > > else > > no input > > end > >There are times when returning multiple values in an array makes sense, >but in this case the values are both really concerned with the same >input, so yes it seems awkward. Either of the other approaches would >seem pretty reasonable. I suppose cancelling is a perfectly legal choice for an user. If this is the case, returning nil sounds better to me than throwing an exception. Just my .02$, Luigi