Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Core and Standard Library Ruby Core Kernel and Object

Rachelle Wood
Rachelle Wood
15,362 Points

Is the .superclass method eliminated for Ruby 2.2.3 ?

Is the .superclass method in Object deprecated for the most recent iteration of Ruby? It looks like it doesn't shot up in the list and I can't seem to use it in the recent version of irb (not the Workspace one but the one that comes with Ruby).

Rachelle Wood
Rachelle Wood
15,362 Points

Hmm... I just did the following test in my version of irb:

object = Object.new

object.respond_to?(:superclass)

=> false

It looks like it has been removed.

1 Answer

Seth Reece
Seth Reece
32,867 Points

According to the docs it is not. I ran IO.superclass in irb and it returned Object just like it says.

Rachelle Wood
Rachelle Wood
15,362 Points

Hmm... I just tried it again. I did (in irb) string = String.new then string.superclass and I got the error message saying that "superclass is not a method for "Hello world!":String.

If I do String.superclass it returns Object. If I define two classes with one inheriting from the other, I get the right superclass. I guess you can only use superclass as a method on classes and not on instantiated variables. I guess that makes sense.

I learned somethink today :)

I guess it's a class method rather than an instance variable then. Good to know!