[ruby-talk:00830] Re: feature request

From: OZAWA Sakuro <crouton@...>
Date: 1999-09-29 04:10:27 UTC
List: ruby-talk #830
At Wed, 29 Sep 1999 12:29:44 +0900,
matz@netlab.co.jp (Yukihiro Matsumoto) wrote:

> How about:
> |	x.gsub!(/(\w)\.(\w)/) { i, j = $~; ... }

What causes the difference below?
The only difference is whether the assignment is done one-by-one or not.

First, I tried this:

x = 'a.b c.d'
x.gsub!(/(\w)\.(\w)/) {
  i, j, k = $~
  print "#{i}, #{j}, #{k}\n"
  j, k = 'zzz', 'ZZZ'
}
p x

=>
a.b, a, b
c.d, c, d
"zzzZZZ zzzZZZ"

Next, I tried this:

x = 'a.b c.d'
x.gsub!(/(\w)\.(\w)/) {
  i, j, k = $~
  print "#{i}, #{j}, #{k}\n"
  j = 'zzz'
  k = 'ZZZ'
}
p x

=>
a.b, a, b
c.d, c, d
"ZZZ ZZZ"

--
OZAWA -Crouton- Sakuro
<mailto:crouton@duelists.org>
<http://www.duelists.org/~crouton/>



In This Thread