2

I have an error:

NoMethodError: undefined method 'some_method?' for #<Customer:0x007f8a2c5d7d80>

Customer is a db-backed AR model. Any way I can actually know which customer is that judging by 0x007f8a2c5d7d80?

How do I translate it into something reasonable?

Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145

2 Answers2

0

Ok, this thread answers my question.

There is no way to determine, which object exactly this was:

Obviously this will be different during multiple runs because it only depends on where the system decided to allocate the memory, not on any property of the object itself.

There's an awesome method - ObjectSpace#_id2ref - it allows to actually find the object by it's object_id:

ObjectSpace._id2ref(object_id)
Community
  • 1
  • 1
Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
0

I found something :)

a = SomethingClass.new
a
# => #<SomethingClass:0x005641a0a3bed8>

0x005641a0a3bed8
#=> 94839867948760

a.object_id * 2
#=> 94839867948760

So in decimal this "werid" code is just doubled object_id

Bartłomiej Gładys
  • 4,525
  • 1
  • 14
  • 24