Created
September 7, 2012 12:46
-
-
Save addisaden/3665955 to your computer and use it in GitHub Desktop.
Evaluator - A small Sandbox in Ruby - key => Sandbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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