Part of my code is as follows:
class Array def square! self.map {|num| num ** 2} self end end
When i call:
[1,2,3].square!
I expect to get [1,4,9], but instead get [1,2,3]. Why is this so? When i call:
[1,2,3].map {|num| num ** 2}
outside the class method, I get the correct answer.
source share