Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Object#id warnings and Active Record

We keep seeing warnings like the following when we run our specs:

Object#id will be deprecated; use Object#object_id

The code in question is accessing the id of an ActiveRecord model (which is an attribute on the table, obviously, rather than the object instance ID in the Ruby VM).

Does anyone know how to turn these particular warnings off or somehow avoid them?

like image 609
Toby Hede Avatar asked Mar 03 '09 23:03

Toby Hede


People also ask

What are Ruby objects in C?

This is how Ruby implements object-oriented code in C: a Ruby object is an allocated structure in memory that contains a table of instance variables and information about the class. The class itself is another object (an allocated structure in memory) that contains a table of the methods defined for that class.

Is Ruby good for OOP?

Ruby supports the OOP paradigm by allowing the creation of classes and its objects. Like we said before, objects are the instances of a class and a class is like the blueprints for the object. A class lists out the attributes and defines the behavior for the object while the object is the real world representation.

How Ruby uses the object structure?

In `ruby`, the body of an object is expressed by a struct and always handled via a pointer. A different struct type is used for each class, but the pointer type will always be `VALUE` (figure 1). In practice, when using a `VALUE`, we cast it to the pointer to each object struct.

Is Ruby 100% object-oriented?

Ruby is a very pure object-oriented language: all values are objects, and there is no distinction between primitive types and object types as there are in many other languages. In Ruby, all objects inherit from a class named Object and share the methods defined by that class.


1 Answers

Try using [:id] instead of .id

like image 162
Ryan Bigg Avatar answered Sep 20 '22 15:09

Ryan Bigg