Skip to content

Instantly share code, notes, and snippets.

@seki
Last active April 24, 2025 15:39
Show Gist options
  • Save seki/773ab9ffe403a5197e82e1a90cb2c583 to your computer and use it in GitHub Desktop.
Save seki/773ab9ffe403a5197e82e1a90cb2c583 to your computer and use it in GitHub Desktop.
require 'singleton'
require 'monitor'
require 'drb'
module DRb
class DRbObjectSpace
include Singleton
include MonitorMixin
def initialize
super()
@map = ObjectSpace::WeakMap.new
end
def to_id(obj)
synchronize do
@map[obj.__id__] = obj
obj.__id__
end
end
def to_obj(ref)
synchronize do
raise RangeError.new("invalid reference") unless @map.include?(ref)
@map[ref]
end
end
end
class DRbIdConv
def to_obj(ref)
DRbObjectSpace.instance.to_obj(ref)
end
def to_id(obj)
obj.nil? ? nil : DRbObjectSpace.instance.to_id(obj)
end
end
WeakIdConv = DRbIdConv
end
if __FILE__ == $0
DRb.start_service(nil, {'stdout' => $stdout, 'ENV' => ENV})
puts DRb.uri
DRb.thread.join
end
@seki
Copy link
Author

seki commented Apr 24, 2025

drb/drb.rbをこんな風に変更して、drb/weakidconv.rbの中身は40行目だけにしたいのだがどうしたらよいのか

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment