Class: Factorial::Lcm

Inherits:
Array
  • Object
show all
Defined in:
lib/factorial/lcm.rb

Instance Method Summary collapse

Constructor Details

#initialize(*number_array) ⇒ Lcm

Returns a new instance of Lcm.



6
7
8
9
# File 'lib/factorial/lcm.rb', line 6

def initialize(*number_array)
  @num_arr = *number_array
  self << manage_the_array_for_lcm
end

Instance Method Details

#manage_the_array_for_lcmObject



11
12
13
14
15
16
17
18
# File 'lib/factorial/lcm.rb', line 11

def manage_the_array_for_lcm
  lcm = 1
  (0..@num_arr.length - 1).each do |i|
    lcm = lcm_method(@num_arr[i], @num_arr[i + 1])
    @num_arr[i + 1] = lcm
  end
  lcm
end