# DAH, using the 'id' property on an object. Get around ruby

**URL:** <https://www.ruby-forum.com/t/dah-using-the-id-property-on-an-object-get-around-ruby/114212>\
**Category:** Ruby\
**Created:** [September 10, 2007, 1:27am UTC](https://www.ruby-forum.com/t/dah-using-the-id-property-on-an-object-get-around-ruby/114212 "2007-09-10T01:27:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [September 10, 2007, 1:27am UTC](https://www.ruby-forum.com/t/dah-using-the-id-property-on-an-object-get-around-ruby/114212/1 "2007-09-10T01:27:08Z")

</div>

DAH, I keep running into issues with using the ID property on an object.  
What is the correct way to use the ID property on an object, without  
pissing Ruby off? In my app I need to be able to use the id property on  
any object. Mostly Object/OpenStruct’s. I’ve had a couple things working  
but then I run into a situation where it doesn’t work correctly. Any  
ideas?

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [September 10, 2007, 1:40am UTC](https://www.ruby-forum.com/t/dah-using-the-id-property-on-an-object-get-around-ruby/114212/2 "2007-09-10T01:40:29Z")

</div>

On Sep 9, 4:27 pm, Aaron S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> DAH, I keep running into issues with using the ID property on an object.  
> What is the correct way to use the ID property on an object, without  
> pissing Ruby off? In my app I need to be able to use the id property on  
> any object. Mostly Object/OpenStruct’s. I’ve had a couple things working  
> but then I run into a situation where it doesn’t work correctly. Any  
> ideas?

Level 1:

obj.object\_id

Level 2:

obj.send(:object\_id)

Level 3:

Object.instance\_method(:object\_id).bind(obj).call

Voyage to the depth you require.

T.

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [September 11, 2007, 5:37am UTC](https://www.ruby-forum.com/t/dah-using-the-id-property-on-an-object-get-around-ruby/114212/3 "2007-09-11T05:37:24Z")

</div>

Trans wrote:

> Level 1:
> 
> obj.object\_id

Level 1.5:  
obj. **id**

Unlike object\_id, redefining **id** causes a warning. I’ve run into a  
case (with rails) where proxy objects forward the object\_id method but  
not the **id** method.

Daniel

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [September 11, 2007, 7:58am UTC](https://www.ruby-forum.com/t/dah-using-the-id-property-on-an-object-get-around-ruby/114212/4 "2007-09-11T07:58:33Z")

</div>

On 9/10/07, Aaron S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> DAH, I keep running into issues with using the ID property on an object.  
> What is the correct way to use the ID property on an object, without  
> pissing Ruby off? In my app I need to be able to use the id property on  
> any object. Mostly Object/OpenStruct’s. I’ve had a couple things working  
> but then I run into a situation where it doesn’t work correctly. Any  
> ideas?

class Object  
undef\_method(:id)  
end

Haven’t had any issues with this so far, and it’s deprecated anyway.

^ manveru

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [September 11, 2007, 9:17am UTC](https://www.ruby-forum.com/t/dah-using-the-id-property-on-an-object-get-around-ruby/114212/5 "2007-09-11T09:17:57Z")

</div>

Michael F. wrote:

> On 9/10/07, Aaron S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > DAH, I keep running into issues with using the ID property on an object.  
> > What is the correct way to use the ID property on an object, without  
> > pissing Ruby off? In my app I need to be able to use the id property on  
> > any object. Mostly Object/OpenStruct’s. I’ve had a couple things working  
> > but then I run into a situation where it doesn’t work correctly. Any  
> > ideas?
> 
> class Object  
> undef\_method(:id)  
> end
> 
> Haven’t had any issues with this so far, and it’s deprecated anyway.
> 
> ^ manveru

That should work perfectly. Thanks.
