Skip to content

Instantly share code, notes, and snippets.

@kenshinji
Created September 22, 2017 16:40
Show Gist options
  • Save kenshinji/4a7e48962cd6685c9b6a7a6094eef202 to your computer and use it in GitHub Desktop.
Save kenshinji/4a7e48962cd6685c9b6a7a6094eef202 to your computer and use it in GitHub Desktop.
flatten an array in ruby
def flattify(array)
array.each_with_object([]) do |element, flattened|
flattened.push *(element.is_a?(Array) ? flattify(element) : element)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment