I can not for the life of me figure this out and I know it is easy but
I can’t seem to find the answer in the API docs or looking at
different plugins but I have a variable that can be different classes
(objects, whatever) and I need to get the class name.
here is an example
asset = User.find(1)
how do I get “User” as a string returned from the asset
thanks I know this is simple but can’t figure it out
I can not for the life of me figure this out and I know it is easy but
I can’t seem to find the answer in the API docs or looking at
different plugins but I have a variable that can be different classes
(objects, whatever) and I need to get the class name.
Sure you really want/need the class name?
If your objects are similar enough that you store them in the same
collection,
does it really matter what class they are?
If they don’t respond to the same method(s), why mix them in the first
place?
here is an example
asset = User.find(1)
how do I get “User” as a string returned from the asset
asset.class.to_s
.class returns the Class of your asset, while .to_s returns the name
of that class or module.
Thanks everyone it was the one thing I didn’t try and man do I feel a
little dumb. To answer some of the questions the asset can be any one
of 5 different classes that I end up running a polymorphic find on so
I needed to get the name of the class to pass to the find.