From: "Ara.T.Howard" Date: 2004-07-16T03:42:16+09:00 Subject: Re: Stumped newbie... On Thu, 15 Jul 2004, flattree wrote: > Here is what I'm trying to do. Simulate nodes with objects. The nodes > > are updated with the class's update method, now where I'm stuck is > > acessing outside variables within the method. > > Simply, how do I refer to an objects state within a method? > > class Gate > def initialize > @state = rand(2) > end > def state > @state > end > def update > @state = a[1].state > end > end > > num = 2 > > a = Array.new > for b in 0..(num - 1) > a[b] = Gate.new > puts a[b].state > end > > puts > puts a[0].state > a[0].update > puts a[0].state > > > Can anyone tell me how to do this? is this what you mean? class Gate def update other @state = other.state end end a[0].update a[1] puts a[0].state i'm not totally clear what 'a' is supposed to be in your original update methods. cheers. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================