Tuesday, November 17, 2009

extended array or specifically enum methods in ruby

The methods available for enum is pretty much useful when we need to make block with the condition. Below are the few example methods:

%w{ ant bear cat}.all? {|word| word.length >= 3} #=> true
%w{ ant bear cat}.all? {|word| word.length >= 4} #=> false
[ nil, true, 99 ].all? #=> false


%w{ ant bear cat}.any? {|word| word.length >= 3} #=> true
%w{ ant bear cat}.any? {|word| word.length >= 4} #=> true
[ nil, true, 99 ].any? #=> true


Enjoy coding...