Why is nil object id 4




















Improve this answer. This lead me to the weirdest bug ever Cool, then the internals has changed between and Just shows never to depend in implementation details ; — dagvl. I'd always assumed it was a cool easter egg: In Japan 4 is the number of death. Andrew Peters Andrew Peters Michiel de Mare LDomagala LDomagala 2, 4 4 gold badges 19 19 silver badges 33 33 bronze badges.

Sumit Munot Sumit Munot 3, 1 1 gold badge 28 28 silver badges 51 51 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.

The Overflow Blog. Much less relevant today with Ruby 1. Less relevant how? TagBit in MRI. I would hope other implementations are permitted to choose different schemes; it would suck if user code began assuming nobody found a use for more than one tag bit. This situation was most encountered by Rails developers trying to access the ID of an ActiveRecord object.

Ah, that was a mistake. ActiveRecord should have avoided :id until it was renamed in core Ruby, or returned some sentinel other than nil whose :id method fails. Assuming Ruby didn't critically depend on :id succeeding for every object, that is. To generate a new ObjectId, use ObjectId with no argument:. In this example, the value of x would be:.

To generate a new ObjectId using ObjectId with a unique hexadecimal string:. In this example, the value of y would be:. Access the str attribute of an ObjectId object, as follows:.

Version 5.



0コメント

  • 1000 / 1000