class FlatArray
attr_reader :nested_array, :result
def initialize(nested_array = [])
@nested_array = nested_array
@result = []
end
def call
flat(nested_array)
result
end
private
def flat(nested_array)
nested_array.each do |element|
element.is_a?(Array) ? flat(element) : @result << element
end
end
end
Last active
August 23, 2017 16:15
-
-
Save IlkhamGaysin/283e0e83bae29efc3488de2ba74035a5 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment