Ok... I'm not sure why there's a semi-debate going on here...

OP asked: "How can I set a value for a class such that all instances of said class get that value change automatically"

I said "you have to change a property on the main class's prototype... a la MyClass.prototype.bSwitch = true;"

Yes, it gives rise to confusion later on and the OP will have to experience this for himself... but if that's what he wants, that's how to do it, and that _is_ what he asked how to do.




On 6/22/06, Gregory Hill <[EMAIL PROTECTED]> wrote:

Which is what I think he's saying as well.  You need to set it at a class level, not at the object level.  Modifying the prototype will not modify all of the instances (according to Andrew, haven't verified it or anything, but I think he's right).  So, if you set a class-level Boolean it should keep it's state across all instances of that class.  Or maybe I haven't woken up yet J

 

Greg

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Ryan Gahl
Sent: Thursday, June 22, 2006 7:27 AM
To: [email protected]
Subject: Re: [Rails-spinoffs] Implementing a boolean "switch" in a Class

 

Right, but the original's poster was looking for precisely a way to chance a property in the main function ("class") and have that change instantly propagate to all instances.

On 6/21/06, Andrew Tetlaw <[EMAIL PROTECTED]> wrote:

On 21/06/06, Ryan Gahl <[EMAIL PROTECTED] > wrote:
> MyObject.prototype.bSwitch = true; is the correct way to achieve what you
> are looking for.

Personally I wouldn't recommend doing this because of the potential
for confusion.

MyObject.prototype.bSwitch = true; is not exactly a class property
because each instance can be changed individually.

You can set it like this, sure
MyObject.prototype.bSwitch = true

and then oMyInstance1.bSwitch = true and oMyInstance2.bSwitch = true

But if you then set oMyInstance1.bSwitch = false; it'll only change it
for the instance and not the class. Which means you are
reading/setting in different ways leading to potential
confusion/mistakes.

--
Andrew Tetlaw
htp://tetlaw.id.au
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

 


_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs



_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to