Skip to content

Instantly share code, notes, and snippets.

@Mon-Ouie
Created September 2, 2011 18:46
Show Gist options
  • Save Mon-Ouie/1189459 to your computer and use it in GitHub Desktop.
Save Mon-Ouie/1189459 to your computer and use it in GitHub Desktop.
require 'pry'
require 'drb'
DRb.start_service
client = DRbObject.new nil, ARGV[0]
# Dummy proxy, DRb won't allow us to pass Readline directly.
Proxy = Object.new
def Proxy.readline(prompt)
Readline.readline(prompt)
end
client.input = Proxy
client.output = $stdout
DRb.thread.join
require 'pry'
require 'drb'
Client = Struct.new(:input, :output)
class Object
def remote_pry
client = Client.new(nil, nil)
DRb.start_service "druby://localhost:5000", client
puts "NOTE: The DRb server is #{DRb.uri}"
# Just loop until we get our client
until client.input && client.output
sleep 0.01 # avoid busy loop
end
input = client.input
output = client.output
# Ensures arity of readline is set to one.
proxy = Object.new
proxy.define_singleton_method :readline do |prompt|
input.readline(prompt)
end
Pry.start(self, :input => proxy, :output => output)
DRb.stop_service
end
end
class Foo
def initialize(x, y)
binding.remote_pry
end
end
Foo.new(0, 50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment