From: "David A. Black" Date: 2005-01-17T23:21:37+09:00 Subject: Re: Fwd: [suby-ruby] Your all time desired fundemental Ruby mod Hi -- On Mon, 17 Jan 2005, trans. (T. Onoma) wrote: > On Monday 17 January 2005 08:20 am, David A. Black wrote: > | Hi -- > | > | On Mon, 17 Jan 2005, trans. (T. Onoma) wrote: > | > I generally agree with you. I wonder if @@vars could just become somesort > | > of across the board initializer/accessor for instance vars (ie. @vars). > | > > | > class C > | > @@a = 10 > | > def a; @a; end > | > end > | > C.new.a #=> 10 > | > | Here you've got one object assigning to another object's instance > | variables, which is not good. > > Except that class vars already do so in a sense in that they are accessable > from both the class level and the instance level. Class vars themselves have that scope, but they don't set instance vars. > But even so, that's not > really what I meant. I'm actually with you on deprecating class vars, and was > instead considering a completely alternate use for @@ notation to mean > "default value of instance vars". This would address the issue in my other > post about initialization of module's instance vars too, i.e. > > module M > @@a = 10 > def a; @a; end > end > > class C > include M > end > > C.new.a #=> 10 > > But maybe you already understood this and still find it not good? Yes :-) You've got one object (M) setting another object's instance variables (those of C.new), without the owner-object's consent. I know that there are already things like instance_variable_set and so on that can do this... but I personally take a pretty hard line on instance variables being strictly the business of the instance whose variables they are. I don't think there should be a proliferation of mechanisms for crossing that boundary. David -- David A. Black dblack@wobblini.net