1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rubyでobject_idからinstanceを探す方法

Posted at

#object_idで取得した値から、そのinstanceを取得する

開発中、たまにチェックする、instanceのobject_id。
object_idは取得は簡単だが、意外と知らない、その逆は!

ObjectSpace._id2ref(object_id)で取得できる!
と言う備忘録です。

integer = 1
#=> 1

object_id = integer.object_id
#=> 3

object = ObjectSpace._id2ref(object_id)
#=> 1

integer.equal?(object)
#=> true
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?