J
Jay McGavren
When working locally with an object whose attribute is meant to store
an array, I have no problem making calls like:
object.items << new_item
If I try to do the same thing with a DRb object, though, appending has
no effect on the remote object. I've distilled the problem down to
this example...
My server:
require 'drb'
class TestServer
attr_accessor :items
def initialize
@items = []
end
def add_item(item)
@items << item
end
def add
sum = 0
@items.each {|item| sum += item}
sum
end
end
server = TestServer.new
DRb.start_service('druby://localhost:9000', server)
DRb.thread.join
My client:
require 'drb'
DRb.start_service()
obj = DRbObject.new(nil, 'druby://localhost:9000')
obj.items << 1 #No effect.
obj.items << 2 #No effect.
items = [1, 2]
obj.items = items #Works.
obj.add_item(1) #Works.
obj.add_item(2) #Works.
puts obj.add #Gives '6' instead of '9'.
I'd rather my client programs be able to use append (<<) instead of an
add_item(item) method or direct assignment. How can I do this?
an array, I have no problem making calls like:
object.items << new_item
If I try to do the same thing with a DRb object, though, appending has
no effect on the remote object. I've distilled the problem down to
this example...
My server:
require 'drb'
class TestServer
attr_accessor :items
def initialize
@items = []
end
def add_item(item)
@items << item
end
def add
sum = 0
@items.each {|item| sum += item}
sum
end
end
server = TestServer.new
DRb.start_service('druby://localhost:9000', server)
DRb.thread.join
My client:
require 'drb'
DRb.start_service()
obj = DRbObject.new(nil, 'druby://localhost:9000')
obj.items << 1 #No effect.
obj.items << 2 #No effect.
items = [1, 2]
obj.items = items #Works.
obj.add_item(1) #Works.
obj.add_item(2) #Works.
puts obj.add #Gives '6' instead of '9'.
I'd rather my client programs be able to use append (<<) instead of an
add_item(item) method or direct assignment. How can I do this?