# Override existing Discourse methods in plugins

**URL:** <https://meta.discourse.org/t/override-existing-discourse-methods-in-plugins/83389>\
**Category:** Developers\
**Tags:** plugin-guides, how-to\
**Created:** [March 20, 2018, 11:37am UTC](https://meta.discourse.org/t/override-existing-discourse-methods-in-plugins/83389 "2018-03-20T11:37:16Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)\
**Post date:** [March 20, 2018, 12:52pm UTC](https://meta.discourse.org/t/override-existing-discourse-methods-in-plugins/83389/2 "2018-03-20T12:52:16Z")

</div>

This is great, thanks for sharing James!

**Overriding instance and class methods**

My fav resource on this is: [https://stackoverflow.com/a/4471202](https://stackoverflow.com/a/4471202)

I use basically the same structure, except I tend to seperate out the module and the prepend.

As you pointed out, this pattern is “super” 😉 useful when trying to avoid overriding core logic.

```plaintext
module InviteMailerEventExtension
  def send_invite(invite)
     ## stuff
     super(invite)
  end
end

require_dependency 'invite_mailer'
class ::InviteMailer
  prepend InviteMailerEventExtension
end

```

One small tip here is that when overriding private or protected methods, your overriding method also needs to be private or protected, e.g.

```plaintext
module UserNotificationsEventExtension
  protected def send_notification_email(opts)
    ## stuff
    super(opts)
  end
end

```

---

_[View the full topic](https://meta.discourse.org/t/override-existing-discourse-methods-in-plugins/83389)._
