Object#id will be deprecated?

I didn’t get the memo on this :stuck_out_tongue:

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

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

I didn’t get the memo on this :stuck_out_tongue:

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

Thanks for enlightening me, Marcel. :slight_smile:

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

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