🖥

Ruby | オブジェクトを表示する時の 16進数って何なの? ( Object#inspect / Object#to_s )

に公開

エンコードされた object_id っぽい。

値を2倍 ( 左に1bitシフト ) して16進数にしたもののようだ。

o = Object.new

p o # #<Object:0x00007f9a3081f098>

p o.object_id # 70150107756620

p o.object_id << 1 # 140300215513240

p (o.object_id << 1).to_s(16) # "7f9a3081f098"

参考

The default to_s prints the object's class and an encoding of the object id.

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2018-06-06

Discussion