[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: class variable weirdness

Gennady Bystritsky

1/26/2006 5:43:00 AM

If you just want to get to a class method from the instance, you can do
a.class.foo=10

Gennady.


-----Original Message-----
From: Alex Combas [mailto:alex.combas@gmail.com]
Sent: Wed 1/25/2006 20:20
To: ruby-talk ML
Subject: Re: class variable weirdness

hi David

On 1/25/06, dblack@wobblini.net <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


--
Alex Combas
http://noodlejunkie.blo...


1 Answer

Alex Combas

1/26/2006 9:26:00 AM

0

On 1/25/06, Gennady Bystritsky <Gennady.Bystritsky@quest.com> wrote:
> If you just want to get to a class method from the instance, you can do
> a.class.foo=10
>
> Gennady.

This is exactly what I was looking for, and
the cool part is that the syntax actually makes sense.
Very apprecaited.

--
Alex Combas
http://noodlejunkie.blo...