Sometimes, when you are working with arrays it is possible to have empty elements,therefore you will need to clean it. In this section I will show you how to remove blank elements from a array using either Ruby on Rails or just Ruby.
Given the array called test
=> ["test", "", 1, 2, ""]
so, to remove the blank elements this is the syntax:
for Ruby on Rails:
test.reject &:blank?
For Ruby:
test.reject &:empty?
No comments:
Post a Comment