# Rewriting method from a plugin - "Self" context

**URL:** https://meta.discourse.org/t/rewriting-method-from-a-plugin-self-context/145215
**Category:** Development
**Created:** [March 23, 2020, 12:20pm UTC](https://meta.discourse.org/t/rewriting-method-from-a-plugin-self-context/145215 "2020-03-23T12:20:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [March 23, 2020, 12:20pm UTC](https://meta.discourse.org/t/rewriting-method-from-a-plugin-self-context/145215/1 "2020-03-23T12:20:24Z")

</div>

Hello,

I’m trying to modify upload instructions from a plugin.

Can I use `add_to_class` to rewrite a class method that is in “self” context?

e.g. to take original method in OptimizedImage class

`def self.resize_instructions(from, to, dimensions, opts = {})`

and overwrite it in plugin with something like  
`add_to_class(:OptimizedImage, :self.resize_instructions) do |from, to, dimensions, opts|`

This is obviously not that straightforward 🙂 ..  
Thanks!

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [March 23, 2020, 5:07pm UTC](https://meta.discourse.org/t/rewriting-method-from-a-plugin-self-context/145215/2 "2020-03-23T17:07:58Z")

</div>

> [@Overgrow](#):
>
> `add_to_class` to rewrite a class method that is in “self” context

You would use `add_class_method`

> <https://github.com/discourse/discourse/blob/main/lib/plugin/instance.rb#L200-L212>
