From: "Mauricio Fernández" Date: 2003-02-02T01:22:46+09:00 Subject: Re: Local variables & blocks On Sat, Feb 01, 2003 at 10:57:42PM +0900, Tom Sawyer wrote: > i realize now that self can't really define the scope. b/c then any definition > would actually bind self to it . i.e. > > class Foo > def bar > self #--> normally instance of Foo, but scope is Foo#bar > end > end > > perhaps having an attribute of the object actually called scope would be of > interest? > > class Foo > def bar > self #--> instance of Foo > scope #--> instance of Foo's bar method > end > end > > thus local variables such as: > > x = 1 > > are in effect: > > scope.x = 1 Then again, instead of calling it 'scope' you can call it local local.x = 1 and then, we make some syntactic sugar: 'local.' <=> '&!@' and we get to &!@x = 1 OH MY GOD! ;-) This is anyway cleaner than self[i], cause the closure only wraps one stack frame. However it is still very powerful as it captures _all_ locals. def foo a = 1 b = 2 scope # gets all the locals end foo.a # 1 It would be possible to implement this in pure Ruby if we could define a macro that used #binding . If you go the way of adding a prefix for locals you cannot possibly beat something like '&local'; moreover that notation doesn't create 'super-closures'. The point is it seems we have something against adding line noise :) Ummm I'm thinking of the weirdness of having instance method objects... class Bar def foo end class << foo def bar # Now, I'm an instance method singleton method. Uh? end iamAlocalOfFoo = true end end If everything is going to be an object, Ruby is going to be Smalltalk ;) -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com * dpkg ponders: 'C++' should have been called 'D' -- #Debian