F
flattree
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 = Gate.new
puts a.state
end
puts
puts a[0].state
a[0].update
puts a[0].state
Can anyone tell me how to do this?
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 = Gate.new
puts a.state
end
puts
puts a[0].state
a[0].update
puts a[0].state
Can anyone tell me how to do this?