DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Use Array#all? To Identify An Array Containing Nil

02.13.2010
| 2731 views |
  • submit to reddit
        Determine if all items in an array are workable object using Array#all? e.g.
['cat', nil, 'bat', 'mat'].all?    #=> false
['cat', 'hat', 'bat', 'mat'].all?  #=> true

Resources:
 - <a href="http://ruby-doc.org/core/classes/Enumerable.html#M003131">Module: Enumerable</a> [ruby-doc.org]    

Comments

Daniel Berger replied on Thu, 2007/07/12 - 4:21pm

Why not just use include?