lib/protocol_buffers/runtime/message.rb in ruby-protocol-buffers-1.5.0 vs lib/protocol_buffers/runtime/message.rb in ruby-protocol-buffers-1.5.1

- old
+ new

@@ -327,13 +327,40 @@ end # Comparison by class and field values. def ==(obj) return false unless obj.is_a?(self.class) - fields.each do |tag, field| - return false unless self.__send__(field.name) == obj.__send__(field.name) + fields.each do |tag, _| + if value_for_tag?(tag) + return false unless (obj.value_for_tag?(tag) && value_for_tag(tag) == obj.value_for_tag(tag)) + else + return false if obj.value_for_tag?(tag) + end end return true + end + + # Comparison by class and field values. + def eql?(obj) + return false unless obj.is_a?(self.class) + fields.each do |tag, _| + if value_for_tag?(tag) + return false unless (obj.value_for_tag?(tag) && value_for_tag(tag).eql?(obj.value_for_tag(tag))) + else + return false if obj.value_for_tag?(tag) + end + end + return true + end + + def hash + hash_code = 0 + fields.each do |tag, _| + if value_for_tag?(tag) + hash_code = hash_code ^ value_for_tag(tag).hash + end + end + hash_code end # Reset all fields to the default value. def clear! fields.each { |tag, field| self.__send__("#{field.name}=", nil) }