Module: SplitInto
- Extended by:
- Simplecheck
- Defined in:
- lib/split_into.rb,
lib/split_into/version.rb,
lib/split_into/split_error.rb
Defined Under Namespace
Classes: SplitError
Constant Summary collapse
- VERSION =
'1.2'
Class Method Summary collapse
Class Method Details
.split(dividend, divisor) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/split_into.rb', line 9 def self.split(dividend, divisor) check(dividend, divisor, Integer, error_message: 'Dividend and divisor must be of type Integer') check(divisor >= 0, error_message: 'Divisor is less than zero') check(divisor <= dividend, error_message: 'Divisor is greater than the dividend') return [] if divisor.zero? parts = Array.new(divisor, dividend.div(divisor)) dividend.modulo(divisor).times { |i| parts[i] += 1 } parts.reverse rescue Simplecheck::CheckFailed => exception raise SplitInto::SplitError, exception. end |