Override precedence

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

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

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

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. [email protected]

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