SHARE
TWEET

Untitled

a guest Aug 24th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # To use this, simply require this file and it will become an extension of the base Array class. As such you can then do
  2. # [1,2,[3]].custom_flatten as in Array.flatten instance method.
  3. class Array
  4.   def custom_flatten(array=self)
  5.     array.each_with_object([]) do |e, flattened|
  6.       flattened.push *(e.is_a?(Array) ? custom_flatten(e) : e)
  7.     end
  8.   end
  9. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top