From: dblack@... Date: 2006-01-26T13:34:54+09:00 Subject: Re: class variable weirdness Hi-- On Thu, 26 Jan 2006, Alex Combas wrote: > hi David > > On 1/25/06, dblack@wobblini.net wrote: >>> Can anyone explain why this is happening? >> [...] >>> puts "%s, %s" % (C.up,C.foo=10) >> >> You need an array there: [C.up, C.foo=10]. The way you've got it, >> what's happening is that it's being parsed as two assignments: >> >> C.up = 10 >> C.foo = nil >> > > Thanks I appreciate the quick reply, I think the () was a bit of > python showing its roots. > What I would like to do now is get instances of those classes and use the > methods that I've defined but I cant figure out how, without changing the class. > > class A > @@foo=1 > def self.foo=(n) > @@foo = n > end > end > puts "%s" % A.foo=10 > a = A.new > #this does not work for an instance > #puts "%s" % a.foo=10 Instances of A don't have a foo method, so you would indeed have to change the class to give them one. Is there a reason you don't want to in this particular case? David -- David A. Black dblack@wobblini.net "Ruby for Rails", from Manning Publications, coming May 1, 2006! http://www.manning.com/books/black