On Wed, May 11, 2011 at 3:29 PM, Frederick Cheung < frederick.che...@gmail.com> wrote:
> On May 11, 7:01 pm, David Kahn <d...@structuralartistry.com> wrote: > > On Wed, May 11, 2011 at 12:52 PM, Frederick Cheung < > > > > frederick.che...@gmail.com> wrote: > > > > > On 11 May 2011, at 18:17, David Kahn <d...@structuralartistry.com> > wrote: > > > > > A question on a couple things relating to extending a class and the use > of > > > super. > > > > > In my main application I have the following class which extends an > engine > > > class: > > > > > You are reopening the class (ie adding/changing methods in User), not > > > subclassing it, so super is looking for methods in activerecord::base. > > > > > Did you want to subclass User instead? > > > > I tried but the thing is that the way the engine loads, the engine class > and > > my class have the same name and reside in the local app. I guess I could > > give my class a different name to subclass it if I dont want to dup the > > code. Was just wondering if there was some other way but logically does > not > > seem that there is. > > > > You another way is to use alias_method_chain - you'd do something like > > class Foo > class << self > def something_with_foo > > end > > alias_method_chain :something, :foo > end > end > end > > What this does is rename the existing something method to > something_without_foo and renames your something_with_foo method to > something. Instead of calling super you call something_without_foo to > call the old something_method > Oh, that is interesting. I guess which would have be used carefully or could get confusing. This will be fun to play with. Thanks! > > Fred > > -- > 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@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- 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@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.