Say I have a plugin like so:
class Plugin
def do_something
do_thing :one
do_something_else
do_thing :two
end
end
If I want to wrap the call to do_something_else in a begin/rescue
block, then it would seem that I need to either hack the plugin in
vendor/ or put a patch in lib/ that copies a portion of do_something.
Either way, it seems I lose on maintainability.
Is there a convention/method for monkey patching existing methods in
plugins in these situations?
Thanks,
Tom Macklin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Jan-08 17:06 UTC
Re: monkey patches to a method that exists in a plugin
On 8 Jan 2009, at 16:37, Tom M wrote:> > Say I have a plugin like so: > > class Plugin > def do_something > do_thing :one > do_something_else > do_thing :two > end > end > > If I want to wrap the call to do_something_else in a begin/rescue > block, then it would seem that I need to either hack the plugin in > vendor/ or put a patch in lib/ that copies a portion of do_something. > Either way, it seems I lose on maintainability. > >The mighty alias_method_chain (which is really just 2 calls to alias_method) can work here class Plugin def do_something_else_with_rescue begin do_something_else_without_rescue rescue ... end end alias_method_chain :do_something_else, :rescue end> Is there a convention/method for monkey patching existing methods in > plugins in these situations? > > Thanks, > Tom Macklin > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---