Skip to content

Instantly share code, notes, and snippets.

@smsohan
Created September 29, 2010 23:37
Show Gist options
  • Save smsohan/603762 to your computer and use it in GitHub Desktop.
Save smsohan/603762 to your computer and use it in GitHub Desktop.
#You have seen something like this, if null replace with a blank array
an_array = (another_array || [] ) + (yet_another_array || [])
#But you could do this as well
an_array = another_array.to_a + yet_another_array.to_a
#Or you have seen this
an_array = another_array + (an_element_or_array.is_a?(Array) ? an_element_or_array : [an_element] )
#But you could do this
an_array = another_array + an_element_or_array.to_a
Happy? I am happy!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment