From: Sausheong Chang on 9 Dec 2009 09:39 Hi I have a slightly different problem. I have an array stored in the object: class Room include DRb::DRbUndumped attr_accessor :name attr_accessor :game attr_accessor :observers def initialize(name=nil) @game = nil @observers = [] @name = name end end And the object is stored at the 'server'. At the 'client' I got the object and is able to modify the @name instance variable at the 'server'. However when I tried to add objects to the @observers array it doesn't seem to appear at the 'server'. What could be wrong? Brian Candler wrote: > Master Marv wrote: >> if a client modifies the status variable of a class instance in the >> array it does not get changed. >> >> dump = DRbObject.new nil, ARGV.shift >> myclass = IEB_wrapper1.new >> dump.push myclass >> dump[0].status = "Hello" >> p dump[0].status => results in "ready" not in "Hello" >> >> how can i modify the status of my class in the array on the drb server? > > class IEB_wrapper1 > include DRbUndumped > end > > This means that instead of passing across a *copy* of the object (made > using Marshal.dump and load), it will pass across a DRb *proxy object*. > All operations made on that proxy are sent across as remote method calls > and therefore made on the server. > > I wrote a document called "DrbTutorial" on rubygarden.org, which > unfortunately is long since gone. You might be able to find a cached > copy somewhere. -- Posted via http://www.ruby-forum.com/.
From: Brian Candler on 9 Dec 2009 10:21 Sausheong Chang wrote: > I have a slightly different problem. I have an array stored in the > object: > > class Room > include DRb::DRbUndumped > attr_accessor :name > attr_accessor :game > attr_accessor :observers > > def initialize(name=nil) > @game = nil > @observers = [] > @name = name > end > end > > And the object is stored at the 'server'. At the 'client' I got the > object and is able to modify the @name instance variable at the > 'server'. However when I tried to add objects to the @observers array it > doesn't seem to appear at the 'server'. What could be wrong? Try this: @observers = [].extend DRb::DRbUndumped I think the same thing is happening one level down: although the Room instance stays where it is, when you make a call across the net to room.observers the return value is a *copy* of this array. Another solution is to remove the attr_accessor for observers completely, and instead implement separate methods for what the client really needs to do - e.g. add an observer, remove an observer, iterate across observers. -- Posted via http://www.ruby-forum.com/.
From: Sausheong Chang on 9 Dec 2009 11:20 Thanks! That worked, though a bit messier than I would have liked it. Brian Candler wrote: > > Try this: > > @observers = [].extend DRb::DRbUndumped > > I think the same thing is happening one level down: although the Room > instance stays where it is, when you make a call across the net to > room.observers the return value is a *copy* of this array. > > Another solution is to remove the attr_accessor for observers > completely, and instead implement separate methods for what the client > really needs to do - e.g. add an observer, remove an observer, iterate > across observers. -- Posted via http://www.ruby-forum.com/.
First
|
Prev
|
Pages: 1 2 Prev: Ruby gem , require and version problem Next: Net::SSH and STDIN / Pending jobs |