0

メソッドが破壊的になり、rake タスク名に bang('!') を追加する場合、Ruby の規則を適用する必要がありますか、それとも unix タイプの標準に準拠する必要があるので、個人的な理解では、bang はあまり使用されません。

例えば。どちらが良いですか?

$ rake update_products   # OR
$ rake update_products!

バックグラウンド

外部 API から製品データを取得し、システム内のレコードを各製品の新しくインポートされたデータで更新する方法があります。

メソッドは次のように呼び出されます。

e = ExternalConnection.new
e.update_products!

rake タスクを作成しているので、これを cron ジョブ/heroku スケジューラーで使用できます。

# scheduler.rake
task :update_products => :environment do
    e = ExternalConnection.new
    e.update_products!
4

1 に答える 1

1

It's up to you and if you want to follow the conventions. Is the update_products method going to modify the e object? If so, we could say that this is a "dangerous method" because the e state is going to change, and maybe somebody else depends on that object.

I, personally would add the "!". Why? Because if another (Ruby) programmer is going to play with the code, he will be like "oh hold on, let's be careful with this".

于 2012-08-11T01:46:26.577 に答える