解决方法
是.
从“Fiddling with Ruby’s Fiddle”:
“You can get the actual pointer value of an object by taking the object id,and doing a bitwise shift to the left. This will give you the pointer (or memory location) of the ruby object in memory.”
使用你的例子i = 5可以像这样做:
i = 5 i_ptr_int = i.object_id << 1 => 22
“In Ruby,why does inspect() print out some kind of object id which is different from what object_id() gives?”有更多关于object_id的信息,包括对您可能会发现有用的实现的C源的简要介绍.
看看“Fiddle”可以做一些其他很酷的事情.