Ruby: Obter o valor de um Fixnum pelo seu object_id

Palavras-chave: Ruby, Fixnum, object_id

Uma jogada legal com objetos do tipo Fixnum em Ruby é descobrir o valor do objeto através do seu object_id, fazendo um simples deslocamento binário:

n = 123456
n.object_id >> 1
=> 123456

Veja outra dica sobre object_id em Ruby.

This entry was posted in Ruby. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>