Class: Factorial::Gcf

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

Instance Method Summary collapse

Constructor Details

#initialize(*number_array) ⇒ Gcf

Returns a new instance of Gcf.



4
5
6
7
# File 'lib/factorial/gcf.rb', line 4

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

Instance Method Details

#manage_the_arrayObject



9
10
11
12
13
14
15
16
# File 'lib/factorial/gcf.rb', line 9

def manage_the_array
  gcd = 1
  (0..@num_arr.length - 1).each do |i|
    gcd = gcd_inner_method(@num_arr[i], @num_arr[i + 1])
    @num_arr[i + 1] = gcd
  end
  gcd
end