Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method · added in Ruby 3.2
Integer#ceildiv
(::Numeric other) -> ::Integer
ceildiv(numeric) → integer
numeric.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/numeric.rb, line 308
def ceildiv(other)
-div(0 - other)
end
Returns the result of division self by numeric. rounded up to the nearest integer.
Example
3.ceildiv(3) # => 1 4.ceildiv(3) # => 2 4.ceildiv(-3) # => -1 -4.ceildiv(3) # => -1 -4.ceildiv(-3) # => 2 3.ceildiv(1.2) # => 3
Ruby version changes
-
3.2
-
Integer#ceildivhas been added. [Feature #18809]
-