Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Ruby Programming Language

alias_method code snippet doubt.

module Mod
     alias_method :orig_exit, :exit
     def exit(code=0)
       puts "Exiting with code #{code}"
include Mod

Above snippet we are creating new alias (orig_exit) for already
existing method exit. Interesting thing is orig_exit is again called
in exit method, why won't this behavior cause recursive calling of
method it self since orig_exit is simply alias to exit method ?

On 5/30/07, Googy <cooldudevam@gmail.com> wrote:

This is a pattern how to preserve original method that you want to override.
Alias stores the method as it was when alias was called. When you
override the method, the alias stil points to the old version --
that's the point of this construct.


On May 30, 1:37 pm, "Jano Svitok" <jan.svi@gmail.com> wrote:

Thanks I am now able to understand whats going on, Until now I used to
assume like alias'ed method and original method point to single
version  of method.

Thanks for clarifying.

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc