Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Check if any Object in an Array is an ActiveRecord instance or not

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

like image 694
Siva Avatar asked Nov 13 '13 12:11

Siva


2 Answers

You can check with:

array.any? { |obj| obj.is_a?(ActiveRecord::Base) }
like image 161
Guilherme Avatar answered Nov 07 '22 19:11

Guilherme


You can check

object.is_a?(ActiveRecord::Base)
like image 26
techvineet Avatar answered Nov 07 '22 20:11

techvineet