While learning ruby with tutorial on rubylearning i got to 'using alias' part of it. I cant understand what is the difference between using alias like in example:
def oldmtd
"old method"
end
alias newmtd oldmtd
def oldmtd
"old improved method"
end
puts oldmtd
puts newmtd
with output
old improved method
old method
and just assigning a new variable to this function, like:
def oldmtd
"old method"
end
newmtd = oldmtd
def oldmtd
"old improved method"
end
puts oldmtd
puts newmtd
with the same output:
old improved method
old method
Please, tell me what is actual difference and when it is correct to use 'alias'?