Challenge for object_id, Garbage Value

I am facing strange problem.

I have an object @part=MainPart.find(:all)

1. @part.each_with_index do |mainpart,index|
2. <p><%= mainpart.object_id%></p>
3. end

          Here problem is that object_id is reserved for rails. Here
object_id field in my table . Now i want to get value <%=
mainpart.object_id%> is giving GARBAGE VALUE. Is there any solution
apart from removing/change object_id field
from table .

Thanks,
Angela .

On Aug 12, 10:56 am, Ruby on Rails <rails-mailing-l...@andreas-s.net>
wrote:

I am facing strange problem.

I have an object @part=MainPart.find(:all)

1. @part.each_with_index do |mainpart,index|
2. <p><%= mainpart.object_id%></p>
3. end

      Here problem is that object\_id is reserved for rails\. Here

It's not just reserved by rails, it is a fundamental ruby method. You
can get the attribute value with read_attribute or [] (which are the
same thing. You could add your own object_id accessor but I'm not sure
whether you would be storing up trouble for later ( object_id is also
available as __id__ but other code might not be expecting object_id to
have been overridden)

Fred

Thanks Fred ,

  I am not getting that concept of ruby . We have nil.object_id is 4
,are they fix for every value, i am not sure for this .By the way thanks
for this.It's working now.

Thanks Again Fred..

Have nice time .

On Wed, Aug 12, 2009 at 10:25 PM, Ruby on

Thanks Fred ,

I am not getting that concept of ruby . We have nil.object_id is 4
,are they fix for every value, i am not sure for this .

No, not in general, and the real story is rather dependent on the
particular Ruby implementation.

If we are talking the MRI (or Matz' Ruby Implementation) then there
are a few objects like nil, true, false... with fixed object_ids, also
FixedNum instances have an object_id which can be computed from their
value.

In general though the object_id is typically related to the address of
the object in memory, so you can't rely on any fixed mapping based on
value, in fact, the object_id which is the identity of the object has
to be independent of the state for a mutable object.

Hi,

Does that mean lets say on a deployed app, the Rails server/stack
starting initiates new object_id's being assigned, are the object_id's
still unique for each object over time (with server restarts etc.) if
they are based on a time algorithm ?

Thanks for your help and clarification on this.

Rajive

No, except for a few objects (and which objects is dependent on the
particularly Ruby implementation, there are no guarantees about the
uniqueness of object_ids over time or even between two daemon
processes running at the same time on the same machine.

It's even conceivable that some implementations might change the id of
an object over time due to the implementation of the garbage
collector, athough I'm not aware of any current Ruby implementations
which do so.

In Ruby, as in life, the concept of identity is more of a
philosophical one than can be relied upon

http://en.wikipedia.org/wiki/Ship_of_Theseus