Skip to content

Instantly share code, notes, and snippets.

@netmask
Created July 20, 2019 01:26
Show Gist options
  • Save netmask/c0a7e7b1e8f221d44e473569ae2f64ac to your computer and use it in GitHub Desktop.
Save netmask/c0a7e7b1e8f221d44e473569ae2f64ac to your computer and use it in GitHub Desktop.
require "minitest/autorun"
module ArrayTools
refine Array do
def flatt
reduce([]) do |new_array, el|
if el.instance_of? Array
new_array += el.flatt
else
new_array << el
end
end
end
end
end
class TestArrayTools < Minitest::Test
using ArrayTools
def test_flatt
assert_equal [1,2,3,4], [[[1,2,[3]],4]].flatt
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment