Convert fields of type Thrift::Types::SET to use the Set library.

Also teach Thrift::Struct how to compare itself with ==


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@668959 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_rb_generator.cc b/compiler/cpp/src/generate/t_rb_generator.cc
index de55c39..16cbe08 100644
--- a/compiler/cpp/src/generate/t_rb_generator.cc
+++ b/compiler/cpp/src/generate/t_rb_generator.cc
@@ -397,7 +397,7 @@
       etype = ((t_set*)type)->get_elem_type();
     }
     if (type->is_set()) {
-      out << "{";
+      out << "Set.new([";
     } else {
       out << "[" << endl;
     }
@@ -407,14 +407,11 @@
     for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
       out << indent();
       out << render_const_value(etype, *v_iter);
-      if (type->is_set()) {
-        out << " => true";
-      }
       out << "," << endl;
     }
     indent_down();
     if (type->is_set()) {
-      indent(out) << "}";
+      indent(out) << "])";
     } else {
       indent(out) << "]";
     }
diff --git a/lib/rb/lib/thrift/protocol.rb b/lib/rb/lib/thrift/protocol.rb
index c4dd762..b514381 100644
--- a/lib/rb/lib/thrift/protocol.rb
+++ b/lib/rb/lib/thrift/protocol.rb
@@ -8,6 +8,9 @@
 # Author: Mark Slee <mcslee@facebook.com>
 #
 
+# this require is to make generated struct definitions happy
+require 'set'
+
 module Thrift
   class ProtocolException < Exception
 
diff --git a/lib/rb/lib/thrift/struct.rb b/lib/rb/lib/thrift/struct.rb
index ce113bf..be46341 100644
--- a/lib/rb/lib/thrift/struct.rb
+++ b/lib/rb/lib/thrift/struct.rb
@@ -44,6 +44,14 @@
       oprot.write_struct_end()
     end
 
+    def ==(other)
+      return false unless other.is_a?(self.class)
+      each_field do |fid, type, name, default|
+        return false unless self.instance_variable_get("@#{name}") == other.instance_variable_get("@#{name}")
+      end
+      true
+    end
+
     protected
 
     def handle_message(iprot, fid, ftype)
@@ -77,10 +85,10 @@
         iprot.read_list_end
       elsif field[:type] == Types::SET
         e_type, size = iprot.read_set_begin
-        value = {}
+        value = Set.new
         size.times do
           element = read_field(iprot, field_info(field[:element]))
-          value[element] = true
+          value << element
         end
         iprot.read_set_end
       else