From: David Flanagan Date: 2007-12-21T06:56:45+09:00 Subject: Re: named captures assigning to local variables Tanaka Akira wrote: > In article , > David Flanagan writes: > >> How about making the return value an array of the captured strings, or nil >> if there was no match? > > Another idea is $~, which is a MatchData or nil. That's simpler to implement than what I had done. And in the simple case when all capturing groups have names, $~ behaves like an array of the captured values, doesn't it? I think I like this. Another option is to raise an exception if the match fails. I can almost convince myself that this is the right thing to do for this kind of assignment... But Ruby is usually more forgiving, so probably not. Another option is to return an empty array when the pattern fails to match, indicating that no values were assigned. This follows the example of: x,y = [] But then you'd have to test the return value with empty? and would have to surround the assignment with parentheses, so the syntax becomes much less pleasant. David