While going through some practice code from a book, I ran into an odd
issue with this do block.
The book put the code this way and it worked fine.
def mtdarry
10.times do |num|
square = num * num
return num, square if num > 7
end
end
num, square = mtdarry
puts num
puts square
This returns 8 and 64, which makes sense.
The problem I ran into is in changing the > to a =.
def mtdarry
10.times do |num|
square = num * num
return num, square if num = 7
end
end
num, square = mtdarry
puts num
puts square
At this point, it outputs 7 and 0. Why does it not calculate the value
of square properly?