You have:
class MyClass
def aMethod
puts "Hi"
end
end
you want to add a feature to aMethod
class MyClass
def aMethod_with_feature
puts "feature"
aMethod_without_feature
end
alias_method_chain :aMethod, :feature
end
Ok, simply put, you have to name the new method 'aMethod_with_feature'. If you want to call the old method, you use 'aMethod_without_feature'. The rest is done by alias_method_chain and your new functionality will be in. Remember that you have to specify the names of the methods as symbols. *thumbs_up*
-alex
References:
“alias_method_bling”
New in Rails: Module#alias_method_chain
Interesting technique using #alias_method_chain
Keine Kommentare:
Kommentar veröffentlichen