Hi,
In message "[ruby-talk:10053] difference between alias and alias_method"
on 01/01/29, "Richard P. Groenewegen" <rpg / xs2all.net> writes:
|Is there a difference between these two pieces of code? Is one of the
|two cheaper than the other?
|
| module Hello | module Hello
| def hi | def hi
| "hi" | "hi"
| end | end
| alias hello hi | alias_method :hello, :hi
| end | end
alias is a statement, so that it's slightly faster than alias_method
which requires method lookup.
|What if hi was a very long and complicated piece of code, possibly
|taking up lots of memory? Is this practical (given that hello will be
|a copy of hi), or is it better to say
|
| def hello
| hi
| end
this one has two differences. (a) it does not protect `hello' from
redefinition of `hi'. (b) it requires two method lookups.
matz.