Syntactic sugar for knowing if all array elements return true for specific method?
arrays, ruby, ruby-on-rails
Solution
There is a very concise way:
array.all? &:blank?
Study `Enumerable` and learn how to use `Enumerator`s and you'll be speaking the most pleasant dialect of Ruby in no time.
Problem
In my Ruby program, I have an array of five strings, and I want to check if each one of the elements of that array match to a given requirement, for example: ``` a = ['', '', '', ''] a.inject(:blank?) # Will return true if (and only if) all elements of a are blank ``` I'm asking this question because Ruby has a pretty large standard API with a lot of pre-written syntactical sugar, which I want to know and don't want to reinvent.