class() vs. type() in Ruby

The key difference is that Object#type is deprecated. From the RDoc for Object#type:

Deprecated synonym for Object#class.

Here’s why you should use Object#class:

Returns the class of obj, now
preferred over Object#type, as an
object‘s type in Ruby is only loosely
tied to that object‘s class. This
method must always be called with an
explicit receiver, as class is also a
reserved word in Ruby.

In reality, you probably want to use Object#respond_to? instead of checking for the class of an object in most cases.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)