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'?
With newmtd = oldmtd
you are not assigning a new variable to a function; you are assigning a variable to the result of a function, that is, a string. In Python terms: newmtd = oldmtd()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With