# Object#id will be deprecated?

**URL:** <https://www.ruby-forum.com/t/object-id-will-be-deprecated/54261>\
**Category:** Rails\
**Created:** [February 28, 2006, 4:02am UTC](https://www.ruby-forum.com/t/object-id-will-be-deprecated/54261 "2006-02-28T04:02:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [February 28, 2006, 4:02am UTC](https://www.ruby-forum.com/t/object-id-will-be-deprecated/54261/1 "2006-02-28T04:02:47Z")

</div>

I didn’t get the memo on this 😛

members\_controller.rb:12: warning: Object#id will be deprecated; use  
Object#object\_id

Line 12 is:  
@member = Member.find(@current\_member.id)

How _should_ I be writing that line?

Thanks,  
Joe

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [February 28, 2006, 4:30am UTC](https://www.ruby-forum.com/t/object-id-will-be-deprecated/54261/2 "2006-02-28T04:30:06Z")

</div>

On Tue, Feb 28, 2006 at 04:02:47AM +0100, Joe wrote:

> I didn’t get the memo on this 😛
> 
> members\_controller.rb:12: warning: Object#id will be deprecated; use  
> Object#object\_id
> 
> Line 12 is:  
> @member = Member.find(@current\_member.id)
> 
> How _should_ I be writing that line?

Object#id is a Ruby method for the internal id of the given object. It  
is a  
method on _every_ object that exists in the execution of your program.  
That  
method is deprecated in favor of Object#object\_id.

## -------------------------------------------------------------- Object#id obj.id =\> fixnum

```
Soon-to-be deprecated version of +Object#object_id+.

```

For example:

> > ‘some string’.object\_id  
> > =\> 2613644
> 
> > %w(an array).object\_id  
> > =\> 2611354
> 
> > Time.now.object\_id  
> > =\> 2608914
> 
> > Object.new.object\_id  
> > =\> 2606434
> 
> > false.object\_id  
> > =\> 0
> 
> > nil.object\_id  
> > =\> 4
> 
> > 25.object\_id  
> > =\> 51

## ------------------------------------------------------- Object#object\_id obj. **id** =\> fixnum obj.object\_id =\> fixnum

```
 Returns an integer identifier for _obj_. The same number will be
 returned on all calls to +id+ for a given object, and no two active
 objects will share an id. +Object#object_id+ is a different concept
 from the +:name+ notation, which returns the symbol id of +name+.
 Replaces the deprecated +Object#id+.

```

This is not to be confused with ActiveRecord::Base#id, which is the  
primary  
key id for a record in your database for a given model. In your case  
@current\_member is, according to your expectation, a Member instance  
when in actuality it is some other object. In the future, once/if Ruby  
gets rid of Object#id entirely, you would get a NoMethodError exception  
here.  
For now, if you get that warning, it means you are calling id on  
something  
that is not an active record. In the development environment, if you  
call id  
on nil a WhinyNil exception is raised, because nil.object\_id is 4 which  
could  
lead to a tricky bug to track down. Any other non-nil/non-active-record  
object you call the id method on will not raise an exception, but you’ll  
get  
that warning from Ruby warning you that Object#id is deprecated.

marcel

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [February 28, 2006, 4:40am UTC](https://www.ruby-forum.com/t/object-id-will-be-deprecated/54261/3 "2006-02-28T04:40:54Z")

</div>

Thanks for enlightening me, Marcel. 🙂

The code that sets @current\_member is:  
@current\_member = Member.find(:first, :conditions =\> ‘…’)

So my guess is that a member wasn’t found, presumably false was  
returned, and then ‘false.id’ was called. Hmm, I’ll have to rethink this  
code…

Joe

---

<div class="post-metadata">

**Author:** ![joe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9e5f3/32.png) [@joe](https://www.ruby-forum.com/u/joe)\
**Post date:** [February 28, 2006, 4:45am UTC](https://www.ruby-forum.com/t/object-id-will-be-deprecated/54261/4 "2006-02-28T04:45:36Z")

</div>

On Tue, Feb 28, 2006 at 04:40:54AM +0100, Joe wrote:

> The code that sets @current\_member is:  
> @current\_member = Member.find(:first, :conditions =\> ‘…’)
> 
> So my guess is that a member wasn’t found, presumably false was  
> returned, and then ‘false.id’ was called. Hmm, I’ll have to rethink this  
> code…

If find(:first) doesn’t find a result it returns nil. So if you are in  
development mode you should be getting an exception raised. If you are  
in  
production mode you won’t get an exception.

marcel
