17

I have an Array of Objects how to check if any one of them is ActiveRecord or not ?

3 Answers 3

25

You can check with:

array.any? { |obj| obj.is_a?(ActiveRecord::Base) }
Sign up to request clarification or add additional context in comments.

Comments

15

You can check

object.is_a?(ActiveRecord::Base)

Comments

0

Suppose obj is the object, one way is to check using === operator of Object class.

array.any? { |obj| ActiveRecord::Base === obj }

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.