このマニュアルは既にメンテナンスが終了したバージョンの Ruby を対象としています。 最新版のマニュアルへ

Ruby 3.1 リファレンスマニュアル

instance method Integer#remainder

remainder(other) -> NumericRuby 2.4.0 から[permalink][rdoc][edit]

selfother で割った余り(剰余)r を返します。

r の符号は self と同じになります。

[PARAM] other:
self に対する除数
p  5.remainder( 3) # =>  2
p  5.remainder(-3) # =>  2
p -5.remainder( 3) # => -2
p -5.remainder(-3) # => -2

p -1234567890987654321.remainder(13731)    # => -6966
p -1234567890987654321.remainder(13731.24) # => -9906.22531493148

[SEE_ALSO] Integer#divmod, Integer#modulo, Numeric#modulo