From: Robert Dober Date: 2009-08-15T00:30:32+09:00 Subject: Re: Class method aliased in superclass bypasses subclass overrides On Fri, Aug 14, 2009 at 4:35 PM, Marcos wrote: > This seems like it should work: > >    class Parent >        class << self >            def real_method() "Parent" end >            alias :fake_method :real_method >        end >    end > >    class Child < Parent >        def real_method() "Child" end >    end > > But it doesn't: > >       Child.fake_method # ==> returns "Parent" instead of "Child" > > If I replace the alias with a real method definition, e.g. > >        def fake_method() real_method end > > then it works the way I expect  (Child.fake_method returns "Child"). > So what is it about "alias" that bypasses the override?   Do I have to > replace my aliases with extra wrapper methods to get the behavior I'm > looking for? > > I do not see anything surprising here, you aliased a method in parent and not in child. When calling child's fake method there is none and the lookup finds the parent's method. When however you wrap the parent's methods after having found parent's #fake it calls real which is found in the child. Note that parent's #real is never called in none of the two cases! HTH Robert -- module Kernel alias_method :ė, :lambda end