Remainder and %

Hi there

puts (-7 % 3)
puts -7.remainder(3)

why the first line returns 2 and the second -1?

Thx

% is an alias for modulo. reminder and modulo differs in negative values, but they give the same results on positive ones.

1 Like