What is "reloadable_patch" exactly?


Still trying to dissect plugins, I was looking to override TopicsController in my studies and searched the Discourse code repo and noticed reloadable_patch

Then I searched for reloadable_patch in Discourse, and got 12 code hits:


So, I decided to look more broadly to try to understand this fascinating “method / hook (?)”, so I:

  • Searched all of Github:
    – All results seem to be related to Discourse (plugins)

  • Searched the web
    – All results seem to be related to Discourse (plugins)

  • Searched meta
    – Got a few hits but nothing which explained reloadable_patch (internals) in details.

Next, I searched the Discourse repo again, and could not find (must be because I am not experienced at this) the “definition” of what, exactly reloadable_patch does (or is defined).

It seems, to a Ruby rookie like me, to be a “method” for a lack of a better word, or a “hook” that facilitates overriding Discourse classes; but I could not find the Ruby code which defines how it works, internally.

Does someone mind to explain this to me or point me to the “defining code” which would explain what reloadable_patch does, from a Ruby internals perspective?


Hopefully, I’m not being a PITA to ask !! :slight_smile:



Its defined here. Hope that helps in digging further.


Thanks so much @fzngagan

Not sure why that def method did not show up when I searched the repo with that keyword; but that is exactly what I was looking for!

Thank you again!!

Edit: I see what happened. I did not look into that instance.rb file deep enough and stopped at the top of the file; but there were 23 entries for reloadable_patch in the file, and the def was at the bottom.

A “def reloadable_patch” in quotes search found it (just now) :slight_smile:

I’m starting to get addicted to Ruby, looking into every nook and cranny.


Explained nicely by @markvanlan