Thrift Tutorial
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665051 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tutorial/rb/RubyClient.rb b/tutorial/rb/RubyClient.rb
new file mode 100755
index 0000000..e0b47b6
--- /dev/null
+++ b/tutorial/rb/RubyClient.rb
@@ -0,0 +1,43 @@
+#!/usr/bin/env ruby
+
+$:.push('../gen-rb')
+
+require 'thrift/transport/tsocket'
+require 'thrift/protocol/tbinaryprotocol'
+
+require 'Calculator'
+
+transport = TSocket.new('localhost', 9090)
+protocol = TBinaryProtocol.new(transport)
+client = Calculator::Client.new(protocol)
+
+transport.open()
+
+client.ping()
+print "ping()\n"
+
+sum = client.add(1,1)
+print "1+1=", sum, "\n"
+
+work = Work.new()
+
+begin
+ work.op = Operation::DIVIDE
+ work.num1 = 1
+ work.num2 = 0
+ quot = client.calculate(1, work)
+ puts "Whoa, we can divide by 0 now?"
+rescue InvalidOperation => io
+ print "InvalidOperation: ", io.why, "\n"
+end
+
+work.op = Operation::SUBTRACT
+work.num1 = 15
+work.num2 = 10
+diff = client.calculate(1, work)
+print "15-10=", diff, "\n"
+
+log = client.getStruct(1)
+print "Log: ", log.value, "\n"
+
+transport.close()