From: Jenda Krynicky Date: 2007-05-25T21:46:38+09:00 Subject: Re: Introducing the "it" keyword Greg Fodor wrote: >> $_ releases after the method. > Ah. This works today: > > return $_ if $_ = opts[:user] > > But it's still hard to read :) At least in one case I know what's the variable here. For $_ that is, opts might be anything. > And don't forget: > > $_ = "foo" > puts $_ if ($_ = "bob" && chomp) > > will print "foo"! Which has nothing to do with $_ or chomp using $_ behind the scenes. It's a problem with operator precedence. It works as if you've written $_ = "foo" puts $_ if ($_ = ("bob" && chomp)) Which means you could get the same confusion if you tried x = 'foo' puts x if (x = 'bob' && 1 > 0) Though there's a chance that the "true" you get in this case would suggest better what's the problem. > (I feel like I'm back writing Perl again) I wish I was. And actually talking about Perl and $_, the way you'd "remember a subexpression to use it several times" would be for () { return $_ if $_ > 45 and f($_) and whatever( 'with', $_) } the difference from $_ = ); return $_ if $_ > 45 and f($_) and whatever( 'with', $_) being that the for(){} localizes the change of $_. That is, $_ only gets the new value within the "loop". Which is something the proposed "it" would have to provide as well. Jenda -- Posted via http://www.ruby-forum.com/.