# Override precedence

**URL:** <https://www.ruby-forum.com/t/override-precedence/152997>\
**Category:** Rails\
**Created:** [November 10, 2008, 11:40pm UTC](https://www.ruby-forum.com/t/override-precedence/152997 "2008-11-10T23:40:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![giorgio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cab0a1/32.png) [@giorgio](https://www.ruby-forum.com/u/giorgio)\
**Post date:** [November 10, 2008, 11:40pm UTC](https://www.ruby-forum.com/t/override-precedence/152997/1 "2008-11-10T23:40:08Z")

</div>

Hi,

I am having trouble overriding methods in a plugin.  
I am trying to apply a patch to attachment\_fu by overriding a method  
in on of the attachment\_fu modules from with a file in my libs folder.

I am using the suggestions from

> **[Emmanuel's Blog](http://epirsch.blogspot.com/2008/01/fixing-attachmentfu-on-windows-like.html)**
>
> Fixing attachment\_fu on Windows Like many others , I've encountered issue when developing Rails applicat...

If I paste the change directly into the atachment fu module the fix  
works. However if I try to make the fix from within my  
attachment\_fu\_patch.rb it doesn’t work and ruby appears to be still  
calling the original method.

This makes me ask the question: If you re-open modules and /or classes  
multiple times and override methods, how does ruby know which one is  
the “latest”. ie how can I ensure that my override is the one that is  
called?

Cheers  
George

---

<div class="post-metadata">

**Author:** ![giorgio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cab0a1/32.png) [@giorgio](https://www.ruby-forum.com/u/giorgio)\
**Post date:** [November 10, 2008, 11:44pm UTC](https://www.ruby-forum.com/t/override-precedence/152997/2 "2008-11-10T23:44:49Z")

</div>

On 10 Nov 2008, at 22:39, giorgio wrote:

> If I paste the change directly into the atachment fu module the fix  
> works. However if I try to make the fix from within my  
> attachment\_fu\_patch.rb it doesn’t work and ruby appears to be still  
> calling the original method.
> 
> This makes me ask the question: If you re-open modules and /or classes  
> multiple times and override methods, how does ruby know which one is  
> the “latest”. ie how can I ensure that my override is the one that is  
> called?

Chronological order of file loading, pure and simple. if files  
overide\_a and overide\_b both define the same method on the same class,  
then if ruby loads a first then the final method definition will be  
the one in b (and vice versa). Ruby isn’t doing any clever tracking of  
anything - stuff just gets overwritten

Fred

---

<div class="post-metadata">

**Author:** ![giorgio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cab0a1/32.png) [@giorgio](https://www.ruby-forum.com/u/giorgio)\
**Post date:** [November 11, 2008, 12:24am UTC](https://www.ruby-forum.com/t/override-precedence/152997/3 "2008-11-11T00:24:42Z")

</div>

Thanks for the reply Fred.  
But that just creates a new question… How do I ensure that my patch  
file is loaded after the plugin?

G.

On Nov 11, 11:44 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![giorgio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cab0a1/32.png) [@giorgio](https://www.ruby-forum.com/u/giorgio)\
**Post date:** [November 11, 2008, 12:27am UTC](https://www.ruby-forum.com/t/override-precedence/152997/4 "2008-11-11T00:27:38Z")

</div>

On 10 Nov 2008, at 23:23, giorgio wrote:

> Thanks for the reply Fred.  
> But that just creates a new question… How do I ensure that my patch  
> file is loaded after the plugin?

stuff in config/initializers should be loaded after plugins.

Fred
