SG 86
SG 86

Reputation: 7078

Is there a better Syntax for my active record select?

I got a user model method called "has_separate_emails?".

Normaly i do somethink like this:

Users.select{ |user| user.has_separate_emails? }

but i wrapped it up to this:

Users.select(&:has_separate_emails?)

the negate version would be:

Users.select{ |user| !user.has_separate_emails? }

And now the question, is there also a shorter/"wrapped" version for negated statements?

Upvotes: 2

Views: 66

Answers (1)

spickermann
spickermann

Reputation: 106932

try

Users.reject(&:has_separate_emails?)

Upvotes: 8

Related Questions