Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/numeric_divide.rb

Instance Method Summary collapse

Instance Method Details

#divide(separation, include_start: false, include_end: true) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/numeric_divide.rb', line 4

def divide(separation, include_start: false, include_end: true)
  unless separation.positive?
    raise ArgumentError, "separation must positive value"
  end

  return [] if self.negative?

  divided_values = 0.step(self, separation).to_a

  unless include_start
    divided_values.shift
  end

  if include_end && divided_values.last != self
    end_value = self
    end_value = end_value.to_f if separation.is_a?(Float)
    divided_values.push end_value
  end

  divided_values
end