TDD/BDD in Ruby - Chapter 7

To-Do List

$5 + 10 CHF = $10 if rate is 2:1
$5 * 2 - $10
Make "amount" private
Dollar side effects?
Money rounding?
equals()
hashCode()
Equal null
Equal object
5 CHF * 2 - 10 CHF
Dollar/Franc duplication
Common equals
Common times
Compare Francs with Dollars
Currency?

Money Code


public boolean equals(Object object) {
  Money money = (Money) object;
  return amoutn == money.amount
    && getClass().equals(money.getClass());
}

Well what do you know... I guess I jumped the gun in Chapter 4 when I implmented == :)


class Money
  attr_reader :amount

  def eql?(object)
    self == (object)
  end

  def ==(object)
    object.equal?(self) ||
      (object.instance_of?(self.class) && object.amount == @amount)
  end
end

Kent Beck calls this code smelly b/c he would "like to use a criterion that makes sens in the domain of finance."