Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个对象数组如何检查其中任何一个是否是 ActiveRecord ?
您可以通过以下方式检查:
array.any? { |obj| obj.is_a?(ActiveRecord::Base) }
你可以检查
object.is_a?(ActiveRecord::Base)
假设obj是对象,一种方法是使用类===的运算符进行检查Object。
obj
===
Object
array.any? { |obj| ActiveRecord::Base === obj }