[ruby-talk:00831] Re: feature request
From:
matz@... (Yukihiro Matsumoto)
Date:
1999-09-29 04:23:58 UTC
List:
ruby-talk #831
Hi,
In message "[ruby-talk:00830] Re: feature request"
on 99/09/29, OZAWA Sakuro <crouton@duelists.org> writes:
|What causes the difference below?
|The only difference is whether the assignment is done one-by-one or not.
Because the evaluated values of the blocks are different. For the
first case:
|x = 'a.b c.d'
|x.gsub!(/(\w)\.(\w)/) {
| i, j, k = $~
| print "#{i}, #{j}, #{k}\n"
| j, k = 'zzz', 'ZZZ'
|}
The evaluated value is the value of the multiple assignment,
which is the array ['zzz','ZZZ'].
On the other hand, for the second case:
|x = 'a.b c.d'
|x.gsub!(/(\w)\.(\w)/) {
| i, j, k = $~
| print "#{i}, #{j}, #{k}\n"
| j = 'zzz'
| k = 'ZZZ'
|}
The value is from the normal assignment, whose value is 'ZZZ'.
Since the gsub methods replaces the matches with the evaluated value
of the given block, the results are different.
Hope this helps
matz.