Skip to content

Instantly share code, notes, and snippets.

@googya
Created April 11, 2014 01:52
Show Gist options
  • Save googya/10436811 to your computer and use it in GitHub Desktop.
Save googya/10436811 to your computer and use it in GitHub Desktop.
show secret when creating a class in Ruby
puts ObjectSpace.count_objects[:T_CLASS]; class Z; end; puts ObjectSpace.count_objects[:T_CLASS]
@googya
Copy link
Author

googya commented Apr 11, 2014

a1 = [];

ObjectSpace.each_object{|e| a1 << e.object_id }; 

class AA; end;

 a2= []; 

ObjectSpace.each_object{|e| a2 << e.object_id }

可以找到新建的两个对象的地址, 然后根据其他属性判断, 哪个是 class, 哪个是 metaclass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment