How do I get the class of a BasicObject instance?

后端 未结 8 2042
小鲜肉
小鲜肉 2020-12-08 03:03

I have a script that iterates using ObjectSpace#each_object with no args. Then it prints how many instances exist for each class.

I realized that some

8条回答
  •  抹茶落季
    2020-12-08 03:25

    If you can upgrade to Ruby 2.0, you don't need to implement anything at all:

    >> Kernel.instance_method(:class).bind(BasicObject.new).call
    => BasicObject
    

提交回复
热议问题