Should I apply the ruby convention when a method can be destructive and add a bang(‘!’) to the rake task name OR do I conform more to unix type standards and hence my personal understanding is that a bang is not often used.
eg. which is better?
$ rake update_products # OR
$ rake update_products!
Background
I have a method which pulls product data from an external API and updates records in my system with the newly imported data for each product.
The method is called like so:
e = ExternalConnection.new
e.update_products!
Im creating a rake task so I can use this in a cron job/heroku scheduler.
# scheduler.rake
task :update_products => :environment do
e = ExternalConnection.new
e.update_products!
It’s up to you and if you want to follow the conventions. Is the
update_productsmethod going to modify theeobject? If so, we could say that this is a “dangerous method” because theestate 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”.