What's the use case for the information supplied by the class method in such cases? What does it really tell me to be of practical use? It doesn't seem to have anything to do with inheritance.
class
works the same way for every object. Calling class
on a class provides the same information as calling class
on an instance. That's because in Ruby, classes are instances, too.
'foo'.class
returns String
because 'foo'
is an instance of String
. Likewise, User.class
returns Class
because User
is an instance of Class
.
In particular, User
is not an instance of ApplicationRecord
.
It might not be obvious that User
is an instance of Class
when creating it via the class
keyword:
class User < ApplicationRecord; end
But it becomes very obvious when you create it explicitly via Class.new
: (both examples produce the same result)
User = Class.new(ApplicationRecord)
User.class #=> Class
Because the above is just like: (using String.new
for demonstration purposes)
foo = String.new('foo')
foo.class #=> String