From: "David A. Black" Date: 2005-03-22T11:56:44+09:00 Subject: Re: RCR 296: Destructive methods return self Hi -- On Tue, 22 Mar 2005, Daniel Amelang wrote: > (3) is an interesting solution to the detection problem. Perhaps > having real multiple return values will solve some other issues in > Rubyland also (anyone?). Using a modified version of the 'strip' > method, let me illustrate a minor modification in the language that > allows for easier use of multiple return values: > > class String > # The new strip returns both the string result and > # a flag that some change occured. > def strip > ... > return result, changed > end > end > > # This works now: > str, changed = "hello ".strip > > # But currently, when you only want the string result, you have to do this: > str, _ = "hello ".strip > > # Because this: > str = "hello ".strip > > # gives you an array :( Actually you can just do: str, = "hello ".strip to assign the first array element to str. That's a nice construct, but it would extremely annoying and feels kind of ad hoc to require it for every strip operation (not to mention sub, gsub, reverse, etc.) Maybe we need StripData, SubData, etc., like MatchData... (No, not really :-) David -- David A. Black dblack@wobblini.net