I'm learning how to use Module.prepend
instead of alias_method_chain
in my Ruby code, and I've noticed that some people use send
to call it (example):
ActionView::TemplateRenderer.send(:prepend,
ActionViewTemplateRendererWithCurrentTemplate)
While others call it directly (example):
ActionView::TemplateRenderer.prepend(ActionViewTemplateRendererWithCurrentTemplate)
And, although I haven't seen anyone use this style, I suspect from the documentation that you could even write this in the module you're prepending from:
module ActionViewTemplateRendererWithCurrentTemplate
# Methods you're overriding go here
prepend_features ActionView::TemplateRenderer
end
Is there some difference between these three styles? Is there a reason to favor one over the others?
prepend_features
is a hook method that is called byprepend
and generally not intended nor designed to be called directly. – Tactic