Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # To use this, simply require this file and it will become an extension of the base Array class. As such you can then do
- # [1,2,[3]].custom_flatten as in Array.flatten instance method.
- class Array
- def custom_flatten(array=self)
- array.each_with_object([]) do |e, flattened|
- flattened.push *(e.is_a?(Array) ? custom_flatten(e) : e)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement