Forum: Ruby on Rails Override precedence

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
15050e11f16301e15da9970a82d2a62f?d=identicon&s=25 giorgio (Guest)
on 2008-11-10 23:40
(Received via mailing list)
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
http://epirsch.blogspot.com/2008/01/fixing-attachm...


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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-10 23:44
(Received via mailing list)
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
15050e11f16301e15da9970a82d2a62f?d=identicon&s=25 giorgio (Guest)
on 2008-11-11 00:24
(Received via mailing list)
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 Cheung <frederick.che...@gmail.com>
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-11 00:27
(Received via mailing list)
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
This topic is locked and can not be replied to.