Print memory address for Ruby array

Pau*_*aul 0 ruby memory arrays pointers

irb> class A; end
=> nil
irb> a=A.new
=> "#<A:0x3094638>"
irb> a.inspect
=> "#<A:0x3094638>"
irb> b=[]
=> []
irb> b.inspect
=> "[]"
Run Code Online (Sandbox Code Playgroud)

How to get memory address of an array object?

Aru*_*hit 5

Use the method 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.

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 > 
Run Code Online (Sandbox Code Playgroud)