syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
In Ruby how do I remove nils from an Array?

Let Ruby run the compacter:
has_nils = [1,2,0,3,7,4,nil,8,1,nil]
# Fails: has_nils.sort
# ArgumentError: comparison of Fixnum with nil failed
no_nils = has_nils.compact
sorted_array = no_nils.sort


syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me