Simplified conditions for Array or any Enumerable objects
1.9.3-p0 :009 > a = [1]
=> [1]
1.9.3-p0 :010 > p 'not empty' if a.any?
=> "not empty"
1.9.3-p0 :006 > a = []
=> []
1.9.3-p0 :007 > p 'empty' if a.empty?
=> "empty"
1.9.3-p0 :012 > [1,nil].all?
=> false
1.9.3-p0 :013 > [1,2].all?
=> true
Written by Jiren Patel
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#