Permalink
Browse files

equalsの一般化

  • Loading branch information...
kk_Ataka kk_Ataka
kk_Ataka authored and kk_Ataka committed Feb 11, 2011
1 parent 599a4f8 commit 5fb8e9ec0545f99cce956c1c6160f953c7a75974
Showing with 15 additions and 19 deletions.
  1. +2 −9 dollar.rb
  2. +2 −9 franc.rb
  3. +9 −0 money.rb
  4. +2 −1 todo.txt
View
@@ -1,14 +1,7 @@
-class Dollar
- attr_reader :amount
- def initialize(amount)
- @amount = amount
- end
+require 'money'
+class Dollar < Money
def times(multiplier)
return Dollar.new(@amount * multiplier)
end
-
- def equals(object)
- return @amount == object.amount
- end
end
View
@@ -1,14 +1,7 @@
-class Franc
- attr_reader :amount
- def initialize(amount)
- @amount = amount
- end
+require 'money'
+class Franc < Money
def times(multiplier)
return Franc.new(@amount * multiplier)
end
-
- def equals(object)
- return @amount == object.amount
- end
end
View
@@ -0,0 +1,9 @@
+class Money
+ attr_reader :amount
+ def initialize(amount)
+ @amount = amount
+ end
+ def equals(object)
+ return @amount == object.amount
+ end
+end
View
@@ -9,5 +9,6 @@
オブジェクトとの等価性
-5 CHF * 2 = 10 CHF
DollarとFrancの重複
- equalsの一般化
+-equalsの一般化
timesの一般化
+ FrancとDollarの比較

0 comments on commit 5fb8e9e

Please sign in to comment.