irb> class A; end
=> nil
irb> a=A.new
=> "#<A:0x3094638>"
irb> a.inspect
=> "#<A:0x3094638>"
irb> b=[]
=> []
irb> b.inspect
=> "[]"
How to get memory address of an array object?
如何获取数组对象的内存地址?
1 个解决方案
#1
3
Use the method Object#object_id
.
使用Object#object_id方法。
Returns an integer identifier for obj. The same number will be returned on all calls to id for a given object, and no two active objects will share an id.
#object_id
is a different concept from the:name
notation, which returns the symbol id of name.返回obj的整数标识符。对于给定对象的所有id调用都将返回相同的数字,并且没有两个活动对象将共享id。 #object_id是一个与:name notation不同的概念,它返回name的符号id。
Example :-
示例: -
Arup-iMac:arup_ruby $ irb
2.1.2 :001 > s = "I am a string"
=> "I am a string"
2.1.2 :002 > obj_id = s.object_id
=> 2156122060
2.1.2 :003 > ObjectSpace._id2ref obj_id
=> "I am a string"
2.1.2 :004 >
#1
3
Use the method Object#object_id
.
使用Object#object_id方法。
Returns an integer identifier for obj. The same number will be returned on all calls to id for a given object, and no two active objects will share an id.
#object_id
is a different concept from the:name
notation, which returns the symbol id of name.返回obj的整数标识符。对于给定对象的所有id调用都将返回相同的数字,并且没有两个活动对象将共享id。 #object_id是一个与:name notation不同的概念,它返回name的符号id。
Example :-
示例: -
Arup-iMac:arup_ruby $ irb
2.1.2 :001 > s = "I am a string"
=> "I am a string"
2.1.2 :002 > obj_id = s.object_id
=> 2156122060
2.1.2 :003 > ObjectSpace._id2ref obj_id
=> "I am a string"
2.1.2 :004 >