Had a thought today about the idiom:
alias :foo_without_bar, :foo
def foo
…
foo_withiout_bar
…
end
First let me point out that Rails recently invented a further bent on
this:
def foo_with_bar
…
foo_withiout_bar
…
end
alias_method_chain :foo, :bar
The trick is the last method which is equivalent to:
alias_method :foo_without_bar, :foo
alias_method :foo, :foo_with_bar
This new idiom is useful when including modules by adding it to the
#included callback. This wookrs finr for the specialized use it gets in
Rails, but it really has issues as a general solution. But I won’t go
into that. That’s not the point of this thread.
This morning it occured to me that an elegant solution might be the use
of a prime mark to do true method wraps:
def foo’
…
foo
…
end
This is essentially like matz ‘def foo:wrap’ but without the extraneous
label. Of course matz hints at having some general use for that label,
if so, I sure would like to know what it is.
Anyhow, just a thought.
T.