lib/veritas/tuple.rb in veritas-0.0.5 vs lib/veritas/tuple.rb in veritas-0.0.6
- old
+ new
@@ -2,12 +2,15 @@
module Veritas
# A set of objects representing a unique fact in a relation
class Tuple
+ extend Comparator
include Immutable
+ compare :data
+
# The tuple header
#
# @return [Header]
#
# @api private
@@ -134,51 +137,38 @@
#
# @return [Boolean]
#
# @api public
def ==(other)
- other = self.class.coerce(header, other)
- data == other.data
+ cmp?(__method__, coerce(other))
end
- # Compare the tuple with other tuple for equality
+ # Return a string representing the tuple data
#
# @example
- # tuple == other # => true or false
+ # tuple.inspect # => "{<Attribute::Integer name: id>=>1}"
#
- # @param [Tuple] other
- # the other tuple to compare with
+ # @return [String]
#
- # @return [Boolean]
- #
# @api public
- def eql?(other)
- instance_of?(other.class) &&
- data.eql?(other.data)
+ def inspect
+ data.inspect
end
- # Return the hash of the tuple
- #
- # @example
- # hash = tuple.hash
- #
- # @return [Fixnum]
- #
- # @api public
- def hash
- self.class.hash ^ data.hash
- end
+ private
- # Return a string representing the tuple data
+ # Coerce an Array-like object into a Tuple
#
- # @example
- # tuple.inspect # => "{<Attribute::Integer name: id>=>1}"
+ # @param [Header] header
+ # the tuple header
+ # @param [Tuple, #to_ary]
+ # the tuple or tuple data
#
- # @return [String]
+ # @return [Tuple]
#
- # @api public
- def inspect
- data.inspect
+ # @api private
+ def coerce(object)
+ self.class.coerce(header, object)
end
# Coerce an Array-like object into a Tuple
#
# @param [Header] header