|
|
|
|
|
by jxf
4420 days ago
|
|
Just that one. The "class" that the method is attached to here is the metaclass of `@user`. That class is below `User` in the hierarchy: class User; def foo; "foo"; end; end
# => :foo
module M; def bar; "bar"; end; end
# => :bar
u = User.new
# => #<User:0x007f2e1abc9e00>
u.extend M
# => #<User:0x007f2e1abc9e00>
u.singleton_class.ancestors
# => [#<Class:#<User:0x007f2e1abc9e00>>,
M,
User,
Object,
PP::ObjectMixin,
Kernel,
BasicObject]
|
|
I'm curious as to whether the ruby-core team implemented method caches for every Object in the system (eg: every instance of User would then have its own method cache because they all would have their own singleton classes) or just objects that are instances of the Class class. I seem to doubt that the former happened because it seems like it would be expensive to maintain a cache for every object, that means a normal Rails request that generates 65,000 strings would all have their own method caches. Only instances of the Class class having their own method caches sounds more reasonable from a performance standpoint to me.
For what it's worth, I've been trying to get an answer about this from a ruby-core member, although my attempts have been quite lazy through Twitter.