I’ve cannibalised discussion from the “Bugs” thread. I hope it is a service to
the community to reopen this. The poll on RubyGarden votes “make 'em all
local”, closely followed by “leave it unchanged”. Yet the “problem” keeps
coming up, and the most sensible solution (in my mind) is not represented in
the poll.
I think it makes sense to explicitly mark external variables, as block-local
variables (parameters, in fact) would be the norm.
Thus, if ‘a’ and ‘c’ are regular parameters and ‘b’ is an external variable,
then one could write
collection.each do |a,:b,c|
…
end
I hereby claim authorship of any syntax derived from the use of
the ‘:’ prefix to indicate the scope of block parameters, based on
[ruby-talk:52401]. All rights reserved.

or
collection.each do |a,b,c|
external b
…
end
I’m not sure which of the above I prefer. One should optimise for the common
case.
I’d head towards ‘:’. Reason: less typing.
Plus we’re used to having ‘@’ and ‘@@’ to indicate scope (kinda), so it
just makes sense for me.
Local params would surely be more common, but marking them with ‘:’
instead of the external ones has the additional advantage of not
breaking any code out there. The transition could be made very easy if
the current scoping rules are mixed with ‘:’ for a while.
So in
blabla.aaaa do |a,:b|
end
a is local if there’s no variable named ‘a’ previously defined,
otherwise external
b is local even if there’s already ‘b’ in the external scope
bottom line: nothing breaks, ‘:’ forces local
Ruby can issue a warning iff there was no ‘a’ variable before, as this
code would break once the old scoping rules are thrown away and only the
presence or absence of ‘:’ is significant.
I’d like to put a question to the audience
Does anyone actually
have a need to use non-local block parameters? Ever?
They are indeed needed sometimes.
···
On Fri, Oct 04, 2002 at 10:58:07AM +0900, Gavin Sinclair wrote:
–
_ _
__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_
_ \ / ` | ’ \
) | (| | |__ \ | | | | | (| | | | |
.__/ _,|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com
Debian is like Suse with yast turned off, just better. 
– Goswin Brederlow