3 ################################################################################
4 # A financial transaction.
5 ################################################################################
7 attr_reader :id, :from, :to, :amount, :date, :description
8 attr_writer :from, :to, :amount, :date, :description
11 def initialize(*transaction_values)
12 from, to, amount, date, description = transaction_values
14 @@id_gen = @@id_gen.succ
15 @from, @to, @amount, @date, @description = transaction_values
18 # Test for equal id of this _Transaction_ against another.
23 # Check whether this object's class is the same as that of the given parameter
24 # and that this transaction's id is the same as that of the given parameter.
26 self.class.eql?(other.class) and @id.eql?(other.id)
29 # Return a unique hash for this transaction, based on its id.
31 # the hash method is called by functions such as Array.uniq. We consider
32 # a Transaction's identity by looking at its id.
36 # Comparison operator. Returns -1, 0 or 1 depending on whether this
37 # _Transaction_ object's compares less than, equally or greater than the given
38 # _Transaction_ object's date.