You should never re-open a class like this, always use class_eval and instance_eval:
Memcache.class_eval do def your_instance_method_here end def self.your_class_method_here end end Using class_eval instead of "re-defining" a class as you did will require the class to be loaded BEFORE your code is run, which is usually what you're looking for. - Maurício Linhares http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr On Mon, Aug 24, 2009 at 1:30 PM, BallaBall<[email protected]> wrote: > > I meant this in a more general way. Where should I put overrides. The > example I listed for ApplicationController was just an example. > > As another example say I want to override something in Memcache. > > class Memcache > # Overrides go here > end > > Where would that go. Should it go in something like app/lib/, config/ > initializers, config/overrides ? > > On Aug 22, 5:54 pm, "Jeffrey L. Taylor" <[email protected]> wrote: >> Why not put it in app/controllers/application_controller.rb? Are you trying >> to override the method for all Rails applications? Unless I do not >> understand >> what you are trying to do, I see no reason to not put it in >> application_controller.rb. This is exactly what this class is for - methods >> common to all controllers. >> >> Jeffrey >> >> Quoting BallaBall <[email protected]>: >> >> >> >> > Thanks Jeffrey but I am aware of this. Like you said it inherits from >> > ActionController::Base but where should this file be kept? >> >> > For example if I reopen the class like: >> >> > module ActionController >> > class Base >> > def override_some_method >> > end >> > end >> > end >> >> > Where should the above code live? Like I said in my first post is that >> > I would create a file name action_controller_overrides.rb and place >> > that in config/initializers but I am unsure if that is the best place >> > to put it. >> >> > On Aug 22, 6:57 am, "Jeffrey L. Taylor" <[email protected]> wrote: >> > > Quoting BallaBall <[email protected]>: >> >> > > > Say I want to extend/override a method on something like >> > > > ActionController. >> >> > > > Where should I put this "monkeypatch"? Currently I am putting it in >> > > > config/initializers but Im thinking there is a better place. >> >> > > app/controllers/application_controller.rb >> >> > > It inherits from ActionController::Base and all other controllers >> > > inherit from >> > > it. > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

