0

I have an array os users called, strangely enough, @users.

Is it possible to search WITHIN this array to further narrow down the results. What I am trying to do is the following

@users.where(:gender => nil)

and end up with a smaller array of users so I can report missing data. is this possible?

1 Answer 1

8
@users.select{|x| x.gender.nil?}

Or do the inverse (if you have no falsey gender)

@users.reject(&:gender)

If @users is a collection of objects you retrieve from a database, you most certainly can do something like:

@users.pluck(:gender)

This get all the non-nil values for most database adapters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.