Skip to content

Instantly share code, notes, and snippets.

@addisaden
Created September 7, 2012 12:46
Show Gist options
  • Save addisaden/3665955 to your computer and use it in GitHub Desktop.
Save addisaden/3665955 to your computer and use it in GitHub Desktop.
Evaluator - A small Sandbox in Ruby - key => Sandbox
require "drb/drb"
require "digest"
class Client
def get_binding
return binding
end
end
class Evaluator
def initialize
@clients = {}
end
def get
a = Digest::MD5.hexdigest (Time.now.to_f + rand(1000000)).to_s
while @clients.keys.include? a
a = Digest::MD5.hexdigest (Time.now.to_f + rand(1000000)).to_s
end
@clients[a] = Client.new.get_binding
return a
end
def evaluate(key, str)
return nil unless @clients.keys.include? key
return eval("#{ str }", @clients[key])
end
end
server = DRb.start_service("druby://localhost:0", Evaluator.new)
puts "Evaluator runs on #{ server.uri }"
server.thread.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment