2

使用している支払いゲートウェイを Subscription クラスと PaymentGatewayApi クラスに抽象化して、モデルに触れることなく将来簡単に変更できるようにします。私のAPIはapp/apiいくつかしかないので問題ないようです(ただし、私よりも賢い人がそうすべきだと言った場合は移動します)。

高品質のコードを記述してパラメーターの呼び出しを減らすには、いくつかの単純なユーティリティ クラスを作成する必要があります。これらの 1 つは、モデルCreditCardCustomerでインスタンス化して、インスタンスを に渡すことができるです。SubscriptionPaymentGatewayApi

私の質問は、このクラスをどこに置くべきですか? 独自のファイルにする必要がありますか、それとも複数のクラスを同じファイルに入れることができますか? Ruby全般と特にRailsのベストプラクティスは何ですか?

4

2 に答える 2

2

My question is, where should I put this class?

Normally these classes lives in \lib. However, if you are planning to use these classes across your projects, you should consider create a gem for it (rails 3 have some nice support for that), and maybe release it as open source?

Does it need to be in its own file, or can I put multiple classes in the same file?

It is usual to have one class per file, but Ruby is not Java, so follow your heart. Try not put two big classes in the same file, for instance. You might want to look at this answer

于 2013-04-26T19:42:32.277 に答える