From: "Mauricio Fernández" Date: 2003-02-15T08:00:24+09:00 Subject: Re: Lexical scope and closures On Sat, Feb 15, 2003 at 07:01:21AM +0900, Tom Sawyer wrote: > on another note: > > this matter has become tricky to deal with because of the way in which ruby > deals with scoping instance variables, vs. instance methods, vs. local > variables, etc. point blank: it is not symmetrical. i wish it could be made > so, but that would of course break code. :-( > > just the same i'll put the idea out here: > > class A > def initialize > # local variables > initialize.a ="instead of just a" > %b = "as sugar for above (used in blocks)" > # instance variables > self.c = "instead of @c" > d = "as above but where self is implied" How do I use A#c then if there's @c? Plus I think locals are more used than i.v. so it makes more sense to prefix the latter... > # class variables > A.e = "instead of @@e" > @f = "this then could be class variable sugar" You forgot my beloved class instance variables :) class << A attr_accessor :e end A.e # class instance variable, NOT class variable > # globals > toplevel.g = "or global.g" > $h = "global sugar" > end > end -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Why are there always boycotts? Shouldn't there be girlcotts too? -- argon on #Linux