Created
June 10, 2011 16:09
-
-
Save cyakimov/1019169 to your computer and use it in GitHub Desktop.
Filter empty strings and nils from array in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#["",nil,"something","another",123,""] => ["something","another",123] | |
array_to_filter.reject &:empty? |
Switch empty?
to blank?
if you want it to work with nil.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will not filter nils: NoMethodError: undefined method `empty?' for nil:NilClass