TechSoft Solutions

Web and Database Development, General Tech tips and Tricks and TechLabs TV IT Training services.

In ruby, there are so many ways of achieving the same functionality using different ways.

In this small article I would like to show different method of defining class Methods in ruby

First way is getting into class’s scope and defining a self method the as follows:

class HisClass
    def self.his_method; end

Second way is to use the name of the class you want to define class method for as follows:

def HisClass.his_other_method; end

Third way is to make use of the eigenclass of which it stores the singleton methods. Note that the class methods are just Singleton methods that lives in class’s eigenclass. We can define it as follows:

class HisClass
  class << self
    def his_method; end

My preferable way is the first which has been embraced the Ruby on rails framework for long time. What is your preferable way for defining a class method  and why?

About Samuel K Itotia

IT Project Consultant, Bachelor of Computer Science holder, Microsoft Certified IT Professional. Certified Google Apps Cloud Deployment specialist and Trainer. Passionate on the new trends of Technology. He will always share it with the world.

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Popular Posts

Can't connect to MyS

This is a simple workaround regarding an error which happened ...

Apache Port 80 colli

Most people that are new to Apache spend most time ...

Building clusters wi

Clustering in Windows Server 2008 has been radically redesigned to simplify ...

What is Rhomobile an

Rhomobile is an open-source Ruby-based mobile development framework for business ...


  • Cheap reliable web hosting from
  • Domain name search and availability check by
  • Website and logo design contests at
  • Reviews of the best cheap web hosting providers at