[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

warhero

9/9/2007 11:27:00 PM

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?
--
Posted via http://www.ruby-....

4 Answers

Trans

9/9/2007 11:39:00 PM

0



On Sep 9, 4:27 pm, Aaron Smith <beingthexempl...@gmail.com> 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.


Daniel DeLorme

9/11/2007 3:36:00 AM

0

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

Michael Fellinger

9/11/2007 5:58:00 AM

0

On 9/10/07, Aaron Smith <beingthexemplary@gmail.com> 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

warhero

9/11/2007 7:18:00 AM

0

Michael Fellinger wrote:
> On 9/10/07, Aaron Smith <beingthexemplary@gmail.com> 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.
--
Posted via http://www.ruby-....