Skip to content

Instantly share code, notes, and snippets.

@eltiare
Created October 22, 2008 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eltiare/18702 to your computer and use it in GitHub Desktop.
Save eltiare/18702 to your computer and use it in GitHub Desktop.
def destroy
sads = self_and_descendents
hooks = self.class.const_get('INSTANCE_HOOKS')
before_methods = hooks[:destroy][:before].map { |hash| hash[:name] }
after_methods = hooks[:destroy][:after].map { |hash| hash[:name] }
# Trigger all the before :destroy methods
sads.each { |sad| before_methods.each { |bf| sad.send(bf) } }
# dup is called here because destroy! likes to clear out the array, understandably.
sads.dup.destroy!
# Now go through after all the after :destroy methods.
sads.each { |sad| after_methods.each { |bf| sad.send(bf) } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment