Ruby’s open classes and modules, along with alias_method, make it really easy to add functionality to existing methods. Take this example from my plugin AttrLocked: class ActionView::Helpers::InstanceTag def tag_with_attribute_locking(name, options = nil) options = (options || {}).update(“disabled” => attribute_locked?) tag_without_attribute_locking(name, options) end alias_method(:tag_without_attribute_locking, :tag) alias_method(:tag, :tag_with_attribute_locking) end All that does is intercept any calls to [...]
© The If Works. Powered by WordPress using the DePo Skinny Theme.