Ruby 调用远程对象
- 作者: 风一样的汉子水灵灵
- 来源: 51数据库
- 2022-08-12
require 'drb'
class Counter
attr_reader:count
def initialize
@count = 0
end
def increment
@count += 1
end
end
counter = Counter.new
DRb.start_service("druby://localhost:8888", counter)
DRb.thread.join
# accesses the Counter object that has been exported by the server:
require 'drb'
DRb.start_service
counter = DRbObject.new(nil, "druby://localhost:8888")
5.times do
counter.increment
puts counter.count
end
推荐阅读
