On 2006-07-21, at 20:53 , Andrew Kaspick wrote:
... My plugin version does not work
though as any form_remote_tag calls are instead being redirected to
version in the other plugin (most likely due to being loaded after my
plugin).
Is there some known way to prevent such issues or to at least warn of
them?
You can use alias_method_chain to wrap the original method call, but
that relies on both plugins using it, and if you're not going to use
the original call, well, it's just counter intuivive. Here's an example
MyPlugin::MyModule
def self.included base
base.alias_method_chain :some_method, :superfun_feature
end
def some_method_with_superfun_feature
do_stuff
some_method_without_superfun_feature
end
end
end
class WhateverIWantToExtend
include MyPlugin::MyModule
end
You can also hook up to the method_defined ruby callback, and issue a
warning whenever a method from your plugin is redefined, or even
alias back your method over the new one (evil).
class ThingIModified
def self.method_added m
return unless m == :do_something
return unless instance_method(m) != instance_method
(:do_something_plugin_version)
warn "do_something redefinition attempt. overriding"
alias do_something do_something_plugin_version
end
def do_something_plugin_version; 1 end
alias do_something do_something_plugin_version
end
t = ThingIModified.new
class ThingIModified
def do_something
2
end
end
t.do_something
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core