Skip to content

Instantly share code, notes, and snippets.

@cherring
Created December 30, 2010 01:53
Show Gist options
  • Select an option

  • Save cherring/759350 to your computer and use it in GitHub Desktop.

Select an option

Save cherring/759350 to your computer and use it in GitHub Desktop.
class KlassB
def do_something
save
send email or some such thing
end
end
class MyKlass
after_save :do_something, :if => :condition_for_callback
def do_something
send_email or some such thing
end
def condition_for_callback
send or not?
end
end
@cherring
Copy link
Author

What are thoughts on callbacks vs just having a method that does something and includes the save inside it? Is it personal taste? Do people not care, or should it be something like have the method that does something but call save separately?

@andys
Copy link

andys commented Dec 30, 2010

My take: do you ALWAYS always always want to send the email every time you save? Then go with the after_save hook.

@cherring
Copy link
Author

Ok so how about if there is a condition on it? like the gist is now?

@andys
Copy link

andys commented Dec 30, 2010

if the condition_for_callback function is going to be used for other stuff, thats cool. or if it'll make it easier to test. if not, it seems like things are getting complex/verbose a bit early perhaps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment