Reputation: 4306
I feel like this is a pretty basic question but I can't seem to find the answer anywhere.
Say I have an array of various things
things = [
false,
#<Product:0x007fc58a2d9ef0>,
12,
"some text"
]
Is there a way I can print out the type of each of those? Something like:
things.each do |thing|
= thing.type
As opposed to having to specifically check if each one is something with thing.is_a? String
Upvotes: 1
Views: 1966
Reputation: 37507
Based on your comments, perhaps you want something like this:
things.select{|t| t.respond_to?(:base_class)}.each do |obj|
#check obj.attr
end
Upvotes: 1