From: Joel VanderWerf Date: 2007-12-20T15:37:04+09:00 Subject: Re: named captures assigning to local variables David Flanagan wrote: ... > My proposal (a patch is below) is to treat named capture assignment as a > new form of assignment. That is: allow regexp literals as lvalues in > assignment. So instead of using =~, we use =. The match is still > performed with =~, but because we use the assignment operator it is > clear that assignment is happening. For example: > > /(?.)(?.)/ = 'foo' > firstchar # => 'f' > secondchar # => 'o' Very nice. Since = is not an operator (and not a method), a certain amount of magic is acceptable (to me). Methods should just be methods. ... > If regexp-based destructuring assignment is popular, this could be > extended to allow other kinds of literals as lvalues. A scanf-style > format string, extended with names could be implemented: > > "%d %d" = "1 2" # Works like x,y=1,2 IMO, the following makes more sense: "#{x} #{y}" = "1 2" but loses the ability to specify conversion. Another possibility: [x, y] = [1, 2] as an alternate form of: (x, y) = [1, 2] -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407