I have spotted a method in some code that does the following :
def method1
method1 = [1, 2, 2, 3, 4, 5, 5]
return method1.uniq!
end
How does ruby handle this? I know this is bad code, but how does the ruby know what to do with ‘method1.uniq!’ ? Should it use the method, or the local variable?
Thanks
You can open a ruby session in a terminal (
irb), type in the code in your question, and see the results yourself.To answer your question, ruby knows the difference between the method
derpand the local variable within its scopederp.