Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/flatten_array/core_ext/array/flatten_array.rb

Instance Method Summary collapse

Instance Method Details

#flatten_array(collection: self, accumulator: []) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/flatten_array/core_ext/array/flatten_array.rb', line 4

def flatten_array(collection: self, accumulator: [])
  collection.each do |element|
    if element.is_a? Array
      flatten_array(collection: element, accumulator: accumulator)
    else
      accumulator << element
    end
  end
  accumulator
end