Docunext


Rails alias method chain

February 23rd, 2011

Today I wrote a plugin for Redmine and ended up using alias_method_chain.

Its a very handy little method! What does do? It allows for convenient overrides of methods built-in to a Ruby on Rails application.

Its syntax sugar, really. This:

alias_method_chain :mymethod, :origmethod

simply encapsulates these two calls:

alias_method :mymethod_without_origmethod, :mymethod
alias_method :mymethod, :mymethod_with_origmethod

A better way to explain this is:

alias_method_chain :mymethod, :achange

which equals:

alias_method :mymethod_without_achange, :mymethod
alias_method :mymethod, :mymethod_with_achange
Yearly Indexes: 2003 2004 2006 2007 2008 2009 2010 2011 2012 2013 2015 2019 2020 2022