Class: Arrayie::Tools
- Inherits:
-
Object
- Object
- Arrayie::Tools
- Defined in:
- lib/arrayie/tools.rb
Overview
This class contains tools for working with Array type
Instance Method Summary collapse
-
#flatten(input_array) ⇒ Array
Flattens a Array type.
Instance Method Details
#flatten(input_array) ⇒ Array
Flattens a Array type
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/arrayie/tools.rb', line 25 def flatten(input_array) unless input_array.is_a?(Array) raise ArgumentError, 'Accepted input should be an Array type.' end input_array.inject([]) do |output_array, item| output_array += item.is_a?(Array) ? flatten(item) : [item] output_array end end |