A Ruby module to demonstrate flattening of a nested array without using Array#flatten
:
Flatten.flatten([1, [2, [3]]])
=> [1, 2, 3]
Code was developed using Ruby 2.3.1. To run tests, run bundle install
and bundle exec ruby flatten_test.rb
For an alternative usage, I also extracted the logic of this custom flatten implementation as a Ruby refinement.