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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to