diff options
| author | mo khan <mo@mokhan.ca> | 2013-04-29 17:08:24 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-04-29 17:08:24 -0600 |
| commit | 804c2557b957bcf81349f95cf334c80904fda1f6 (patch) | |
| tree | e2a83c43d915d433dd56d91d6e73152a41dae7fa | |
| parent | 6de610122a4fe6f15d4b34fb15b47d3a2069ce88 (diff) | |
add simple money together
| -rw-r--r-- | lib/money.rb | 8 | ||||
| -rw-r--r-- | spec/unit/money_spec.rb | 6 |
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/money.rb b/lib/money.rb index b8ae962..11394e6 100644 --- a/lib/money.rb +++ b/lib/money.rb @@ -5,6 +5,14 @@ class Money @amount = amount end + def +(other) + plus(other) + end + + def plus(other) + Money.new(@amount + other.amount) + end + def ==(other) @amount == other.amount end diff --git a/spec/unit/money_spec.rb b/spec/unit/money_spec.rb index 0120c60..9716db2 100644 --- a/spec/unit/money_spec.rb +++ b/spec/unit/money_spec.rb @@ -15,4 +15,10 @@ describe Money do end end end + context "when adding money" do + it "should return the new amount" do + result = Money.new(1.99) + Money.new(0.01) + result.should == Money.new(2.00) + end + end end |
