+ 1

Ruby - What does this code do?

And why output is 1,2,3? arr = [1,2,3] puts arr.each{ |x| x = -x}

22nd Sep 2019, 8:36 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
1 Answer
0
I'm not sure what exactly you want if you want the output to be negative. It should be arr.each{ |x| puts -x} not puts arr.each{ |x| x = -x}
22nd Sep 2019, 8:46 AM
Phurinat Puekkham
Phurinat Puekkham - avatar