Hi,
In message "[ruby-talk:15954] new keyword idea: tryreturn, tryturn or done"
on 01/05/30, Juha Pohjalainen <voidjump / nic.fi> writes:
||----------------------------------------------------------
|| def doSomethingWith value
|| result = tryFirstThing value
|| return result if result
|| makeSomePreparations value
|| result = trySomethingElse value
|| return result if result
|| raise TypeError, "could not do it"
|| end
||----------------------------------------------------------
|
|Or what do you think?
|
||----------------------------------------------------------
|| def doSomethingWith value
|| tryturn tryFirstThing value
|| makeSomePreparations value
|| tryturn trySomethingElse value
|| raise TypeError, "could not do it"
|| end
||----------------------------------------------------------
def doSomethingWith value
return tryFirstThing value ||
(makeSomePreparations value;
trySomethingElse value) ||
raise(TypeError, "could not do it")
end
or
def doSomethingWith value
return tryFirstThing value ||
(makeSomePreparations value;
trySomethingElse value or
raise TypeError, "could not do it")
end
matz.