Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Ruby Programming
Previous Page Home Next Page
class Class
Parent: Module
Version: 1.6


inherited new new superclass

Classes in Ruby are first-class objects---each is an instance of class Class.

When a new class is created (typically using class Name ... end), an object of type Class is created and assigned to a global constant (Name in this case). When is called to create a new object, the new method in Class is run by default. This can be demonstrated by overriding new in Class:

class Class
   alias oldNew  new
   def new(*args)
     print "Creating a new ",, "\n"

 class Name  end

 n =
Creating a new Name

class methods
inherited aClass.inherited( aSubClass )

This is a singleton method (per class) invoked by Ruby when a subclass of aClass is created. The new subclass is passed as a parameter.

class Top
  def Top.inherited(sub)
    print "New subclass: ", sub, "\n"

class Middle < Top end

class Bottom < Middle end
New subclass: Middle
New subclass: Bottom

new aSuperClass=Object ) -> aClass

Creates a new anonymous (unnamed) class with the given superclass (or Object if no parameter is given).

instance methods
new [ args ]* ) -> anObject

Creates a new object of aClass's class, then invokes that object's initialize method, passing it args.

superclass aClass.superclass -> aSuperClass or nil

Returns the superclass of aClass, or nil.

Class.superclass Module
Object.superclass nil

Ruby Programming
Previous Page Home Next Page

  Published under the terms of the Open Publication License Design by Interspire