Ruby 调用远程对象

2015-04-19 0 640
Ruby 调用远程对象
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

遇见资源网 ruby Ruby 调用远程对象 http://www.ox520.com/16315.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务