Ruby - return true if any element in Array satisfies condition but false otherwise

Hi,

A Ruby question.

Anyone know a function that loops through an array and returns true if
any one element satisfies the condition but false if none satisfy the
condition? And it should do this in one line. Something like

any_bot_follower = followers.each {|f| return true if f.bot?}

The above returns an array if none of the Array elements satisfy the
condition. I want it to return false instead.

I have seen a function somewhere that does this but just not able to
nail it down. Hoping one of you here would know.

Thanks!

Hi,

A Ruby question.

Anyone know a function that loops through an array and returns true if
any one element satisfies the condition but false if none satisfy the
condition? And it should do this in one line. Something like

any?

Fred

Perfect! :slight_smile: thanks! Couldn't find docs on this though.

Array includes module Enumerable. 'any?' can be found in Enumerable.