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 . -- Posted via http://www.ruby-forum.com/.
On Aug 12, 10:56 am, Ruby on Rails <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I am facing strange problem. > > I have an object @part=MainPart.find(:all) > > 1. -oRIsQWQClC3tRgLqZ5aouw@public.gmane.org_with_index do |mainpart,index| > 2. <p><%= mainpart.object_id%></p> > 3. end > > Here problem is that object_id is reserved for rails. HereIt''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> 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 . > -- > Posted viahttp://www.ruby-forum.com/.
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 . -- Posted via http://www.ruby-forum.com/.
On Wed, Aug 12, 2009 at 10:25 PM, Ruby on Rails<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale
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 On Aug 13, 12:42 pm, Rick DeNatale <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Aug 12, 2009 at 10:25 PM, Ruby on > > Rails<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > 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. > > -- > Rick DeNatale > > Blog:http://talklikeaduck.denhaven2.com/ > Twitter:http://twitter.com/RickDeNatale > WWR:http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn:http://www.linkedin.com/in/rickdenatale
On Mon, Sep 14, 2009 at 1:39 PM, rkj2 <rajive.jain-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 ?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 -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale
Possibly Parallel Threads
- Possible to ask rspec to show more code in the debugger?
- Anyone using the rspec textmate bundle with Ruby 1.9.1
- Any pioneers who've configured passenger to support some apps running in 1.8.x others in 1.9?
- Class method not being stubbed
- Problems running features with Textmate Cucumber bundle