Closed robg closed 13 years ago
Can you please explain why it s better to check for instance_methods?
I'm guessing the reason for this guard is so that the helper isn't overwriting any existing methods. Since it is defining an instance method, it makes sense to check there rather than at the class level. If I add some logging to this block, you can see that the class level check is pretty ineffective. In this scenario, my Company model has already defined a delete_logo method for its logo attachement:
Generating Paperclip delete methods for logo in Company
Klass method defined: false
Klass instance method defined: true
After Paperclip delete method defined for logo in Company
Klass method defined: false
Klass instance method defined: true
This fixes the conditional guard to check against instance methods rather than class methods before defining the delete_attachment methods.