class TCPSocket

Public Instance Methods

accept_loop() { |input| ... } click to toggle source
# File lib/rapel.rb, line 18
def accept_loop
  loop do
    message = JSON.parse(self.gets.chomp, symbolize_names: true)
    $stdout.puts("Message received: #{message} from: #{self}")
    case message[:op]
    when "eval"
      $stdout.puts("Eval message recieved: #{message[:code].inspect}")
      begin
        Rapel::REPLServer::Input.new("qer")
      rescue
        puts $!
      end
      yield Rapel::REPLServer::Input.new(message)
    else
      break
    end
  end
  close
end
repl() click to toggle source
# File lib/rapel.rb, line 38
def repl
  accept_loop do |input|
    input.read do |expression, context|
      expression.evaluate(context) do |result|
        respond_with(result)
      end
    end
  end
end
respond_with(result) click to toggle source
# File lib/rapel.rb, line 48
def respond_with(result)
  response = result.to_json
  self.puts response
  $stdout.puts "returned #{response} to #{self}"
rescue Exception => e
  $stdout.puts e.inspect
end