Money 素振りめも
Moneyを素振りして気づいたんだが、パタンやイディオムが、いろいろ隠れている。
Nested Closure(DSLs)
describe "Money" do ... context "比較演算" do it "" do ... end end ... end
この種の構造化、業務系ドメインの Production Code でデザインしてみたい。
Literal Extension(DSLs)
1000.yen
DynamicReception?(DSLs)
(xxx).should be_true
(追記) DynamicReceptionじゃなさそう。。。
Quantity(Analysis Patterns), Value Object,
Money クラス。
Side Effect Free Function(DDD)
def +(other) .... Money.create(self.amount + other.amount, self.currency) end
Value Object と相性のいいパタン。
Open Class
class Fixnum def yen Money.create(self, :yen) end def dollar Money.create(self, :dollar) end end
他にも隠れてそう。